Get In Touch
113 Cherry St #92768,
Seattle, WA 98104-2205
[email protected]
Back

How to avoid crashes when using GCM in your android app

I recently introduced GCM to an android app I developed. I used an SaaS service called Pushbots. You should try them if you want analytics for your GCM app and you don’t want to go into all the stress of building a backend app. After developing my app, I tried using the emulator to test but I kept getting crashes. I emailed support and within 5 minutes I got a response that indicated to me that I was using an emulator that doesn’t have any of Google’s packages. This post from StackOverflow explains this further. Anyways, I was pretty sure my code was right but couldn’t adjust my emulator settings. All you need to throw and catch an exception. After which you can send a Toast message or whatever you want. You can do it this way:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);    
    try {
        hereIsYourGCMCode();
    } catch (UnsupportedOperationException e) {
        Toast.makeText(activity, R.string.gcm_not_supported, Toast.LENGTH_SHORT).show();
    }
}

This website stores yummy cookies on your computer. Cookie Policy