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.
Go to your Google Account. On the left navigation panel, select Security . On the Your devices panel, select Manage all devices. You'll see devices where you're currently signed in to your Google Account or have been in the last few weeks.
In the Users list, find the user. If you need help, see Find a user account. The account status is shown in the Status column. If the user's account status is in red text or suspended, click the user's name to open their account page.
Google now gives you Android notifications when new devices log into your accounts. Android users will be told of new device logins to their Google accounts via a notification on the smartphone rather than by email.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With