Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if users google account has been added on device before starting GCM procedure?

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.

like image 420
Harry Avatar asked Nov 23 '12 13:11

Harry


People also ask

How do I know if my Google account has been granted?

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.

How to know if Gmail account is active or not?

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.

Does Google tell you when you login from another device?

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.


1 Answers

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

like image 126
NickT Avatar answered Oct 16 '22 23:10

NickT