Check synced account in android programatically
<p>As I am using GCM in my application so for android we need to have a synced Gmail account to get register with GCM.I am able to get whether the account is synced or not by using the simple code  given below </p>

<pre><code>AccountManager am = AccountManager.get(this);
Account[] accounts = am.getAccountsByType("com.google");
boolean syncEnabled = ContentResolver.getSyncAutomatically(accounts[0], ContactsContract.AUTHORITY);
if(){
    // do register with GCm
}else{
    //ask to sync
}
</code></pre>

<p>But the problem which I am facing is when user changed the SIM card in the device the Gmail account will give a notification with red error icon to enter the password while trying to register on GCM through app but sync is enabled because user doesn't clear the checkboxes required in sync under account and sync setting and in that case synEnabled is always  true but it is not actually and my application will not show any error for syncing to user but will fail in registration.</p>

<p>Then what is the best approach to handle this type of situation. </p>
