Search code examples
androidandroid-c2dm

Android, looking for a simple way to accurately determine if a device is C2DM capable?


I'm looking for the simplest way to write a boolean function that will tell me if the device the app is running on is capable of using C2DM.

I am aware that the presence of the Android Google Play app is guaranteed to ensure C2DM capability but not all devices have this and are still C2DM capable

As far as I can tell, The device needs to have the GSF installed (Google Services Framework) and a valid GMail account set up and these are the only requirements to guarantee C2DM will work. Is this accurate?

If so would a check for the existence of the GMail package and the Google Services Framework package be the best and most accurate approach?


Solution

  • Very quick an dirty but the concept remains, if you DO wish to simply search for the presence of the Google services framework you can use the below.

    I only post this because AFAIK there isn't another obvious method.

     boolean installed  =   appInstalledOrNot("com.google.process.gapps");
            if(installed)
            {
                      System.out.println("App installed on phone");
            }
            else
            {
                System.out.println("App is not installed phone");
            }
        }
        private boolean appInstalledOrNot(String uri)
        {
            PackageManager pm = getPackageManager();
            boolean app_installed = false;
            try
            {
                   pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES);
                   app_installed = true;
            }
            catch (PackageManager.NameNotFoundException e)
            {
                   app_installed = false;
            }
            return app_installed ;
    }