I have made an application which is using GCM push messaging framework for getting push messages from server.But the problem is application will not be able to register on GCM server if google account is not synced in device. So what I want do notify the user about to sync an account first to proceed.
I am able to get whether the account is synced or not by using the following code:
AccountManager am = AccountManager.get(this);
Account[] accounts = am.getAccountsByType("com.google");
boolean syncEnabled = ContentResolver.getSyncAutomatically(accounts[0], ContactsContract.AUTHORITY);
Log.d("ACCOUNT SYNC", "syncStatusofaccount"+syncEnabled);
if(!syncEnabled){
setContentView(R.layout.login);
AlertDialog alertForAccounrtSync=new AlertDialog.Builder(this).create();
alertForAccounrtSync.setTitle("Account Sync");
alertForAccounrtSync.setMessage("Sync your Gmail Account before proceed");
alertForAccounrtSync.setCancelable(false);
alertForAccounrtSync.setButton("Sync Account", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
});
alertForAccounrtSync.show();
Now on press of button I just want to call Account and Sync setting directly so that it will be good experience for user.
But the question is How?? what should i write in Onclick() function Please Help.
I got the anser myself
Thank you may be it will be useful for others.