How to check if users google account has been added on device before starting GCM procedure?
android, google-cloud-messaging, notifications
Solution
I had a look at the source for checkDevice() and as far as I can see it only checks the API level and that the gcm package is on the device. So following on from CommonsWare's suggestion, this code appears to do the job for me:
private boolean deviceHasGoogleAccount(){
AccountManager accMan = AccountManager.get(this);
Account[] accArray = accMan.getAccountsByType("com.google");
return accArray.length >= 1 ? true : false;
}
You will need the line
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
in the manifest
Problem
Is there a way to check if user has added his google account on his device before starting the GCM registering procedure API 8? When try to register without it the app gives a warning stopped unexpectedly when closing, so like to check first, alert the user and close the app.