1

Is there a way to programmatically check if an Android device is running Google Services? I have an application that utilizes C2DM and want to disable menu options including this if the device (such as Kindle Fire and Nook) do not have the Google Services required.

taraloca
  • 9,077
  • 9
  • 44
  • 77

2 Answers2

3
public static boolean doesContainGsfPackage(Context context) {
        PackageManager pm = context.getPackageManager();
        List<PackageInfo> list = pm.getInstalledPackages(0);

        for (PackageInfo pi : list) {
            if(pi.packageName.equals(ACCUWX.GSF_PACKAGE)) return true;  // ACCUWX.GSF_PACKAGE = com.google.android.gsf

        }

        return false;
     }
taraloca
  • 9,077
  • 9
  • 44
  • 77
1

I am not sure exactly what "Google Services" is however in the past I have found this function reliable when testing if a service is running. By replacing "some.package.name.MyService" with the Google Services package name then you should be able to check if it is running or not.

    private boolean isMyServiceRunning() {
       ActivityManager manager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
       for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
           if ("some.package.name.MyService".equals(service.service.getClassName())) {
              return true;
           }
       }
       return false;
    }
Mike Baglio Jr.
  • 1,990
  • 3
  • 18
  • 19
  • I needed to find the package containing and therefore used the solution that I posted. Thanks for the attempt! – taraloca Feb 16 '12 at 15:44