Android - Getting Google Account Sync Settings - android

I'm trying to find out if the user has Google-Photos (picasa) set to sync on their device. Is there any way to programmatically determine whether sync is turned on for any of the google accounts set up on the user's phone?
Also, is there any way to programmatically turn synching off for Google-Photos? If not, what is the correct Intent to launch an activity directly to the Google account's "Data & Synchronization" screen, so that the user can manual disable sync?
Thanks in advance!
EDIT:
I found some code that is useful, but what is the Authority string for "Google-Photos" (aka Picasa)???
import android.provider.ContactsContract;
AccountManager am = AccountManager.get(this);
Account[] accounts = am.getAccountsByType("com.google");
boolean syncEnabled = ContentResolver.getSyncAutomatically(accounts[0], ContactsContract.AUTHORITY);

There are two case
1) If your device is already synchronize with Google account
Then Account selector will select current login account.Refer this link
2) If your account selector does not return any account that means you are not login with any Google account. So you need to synchronize.Now in this case open your account screen and one account This will help you

Related

Disable user account for FRP, allow only work managed accounts

Prelude:
The client wants to install EMM for his owner devices. Sometimes the user wants to use the device as work device (only taxi and couriers apps) and sometimes the user wants to use the device as his own (install games, social apps, and his own Google accounts).
Situation:
The client wants to store his gsuite accounts in FRP storage (to have the ability to unlock a phone in case employee leave organization) but doesn't want an employee to unlock the phone after FR entering his personal account credentials.
Example:
I added two work account programmatically (like described here). But after the user gets the phone he entered his personal Gmail account to use Gmail, other apps. How can I programmatically or maybe from DPC app prevents user recover access to the phone using his personal account after Factory Reset?
I found the answer, finally. The link to the documentation.
I need just to create a bundle with google plus ids of accounts that will have the opportunity to recover device after factory reset.
And after that need to send a broadcast to notify the system that these values were changed.
val bundle = Bundle()
// list of recovery accounts
val recoveryAccounts = arrayOf(
"115273111154663031432",
"110369192556268846321",
)
bundle.putStringArray("factoryResetProtectionAdmin", recoveryAccounts)
mAdminComponentName = DeviceAdminReceiver.getComponentName(context)
// set restrictions
mDevicePolicyManager.setApplicationRestrictions(mAdminComponentName, "com.google.android.gms", bundle)
// send broadcast
val broadcastIntent = Intent("com.google.android.gms.auth.FRP_CONFIG_CHANGED")
broadcastIntent.setPackage("com.google.android.gms")
broadcastIntent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND)
applicationContext.sendBroadcast(broadcastIntent)
Off topic.
To get the id of recovery accounts try this: https://developers.google.com/people/api/rest/v1/people/get?apix=true&apix_params={"resourceName":"people/me","personFields":"metadata"}
Push "Execute" and login with needed account. It'll be shown in "id" field of response.

Using ADB or Appium, programmatically remove linked account from Android Settings

How can I programmatically remove/clear a linked account from an Android device within Android Settings > Accounts? Is this possible with ADB or Appium, or by some other programmatic method?
Android devices typically keep linked accounts for Google or Facebook on a device settings level, not within a single app's cache. I would like to remove these accounts (especially Facebook, which appears to only have one account per device).
The context for the question is in automated testing.
Removing accounts manually/by hand is not an option.
I'd prefer not to do it via Appium UI automation; even if Appium could solve this problem on one device, different android devices/OS versions have different settings UI, thus UI automation is not a scalable solution.
The best, easiest, and most scalable solution would allow me to do an ADB command which could remove the linked account.
Edit:
Here is an unanswered question on Appium forums asking a similar question: https://discuss.appium.io/t/android-how-to-remove-google-accounts-linked-a-device-on-setting-activity/6920
Linked accounts are stored in the database /data/system_ce/0/accounts_ce.db, to access it you need root access.
In the case if you have root access you can simply remove the entry of the specified account from the database.
I had the same question, and found something to remove ALL accounts.
Take a look at what AuthenticatorDescription types you are getting if you strictly only want to delete e.g. Google Accounts
private void clearAccounts() {
AccountManager manager = AccountManager.get(getApplicationContext());
AuthenticatorDescription[] authTypes = manager.getAuthenticatorTypes();
for (AuthenticatorDescription authDesc : authTypes) {
Account[] accounts = manager.getAccountsByType(authDesc.type);
if (accounts.length == 0) {
continue; // No accounts of this type, continue loop.
}
for (final Account account : accounts) {
manager.removeAccount(account, null, null, null);
}
}
}

how to add google account programmatically in android with one click in background?

i am trying to add google account programmatically to android using a app that takes username and password and logins the user in background. But i m having problem as it is showing error...
Error: Caller uid 10024 is different than authenticator's uid .
I had already included all permissions and authenticator xml but it is not responding...
plz help i want to add google account in backgroundwith one click ..
Thanks in advance..
Account acc = new Account("mygmailid#gmail.com", "com.google");
AccountManager am = AccountManager.get(this);
Bundle userdata = new Bundle();
userdata.putString("SERVER", "extra");
if (am.addAccountExplicitly(acc, "mypass", userdata)) {
// success message..
}
Basically this would be impossible to do because adding an new google account without the prior information of the user itself would definetely be a kind of malware or theft app.
Therefore according to Google this would lead to violate the user freedom and its trust towards Android operating system.
But you can add new google account and can ask user to enter the password for that account. So there will be no permission violation.

Synching accountmanager accounts

I am writing an android application that will start sync for all accounts added under "Account & sync" settings.I am fetching all the added accounts using the following code
AccountManager am = (AccountManager) getSystemService(Context.ACCOUNT_SERVICE);
Account[]acs = am.getAccounts();
After fetching the account I want to start sync for each account
for(Account ac:acs){
ContentResolver.requestSync(ac,authority,extras);
}
My question is how do i fetch the authority for the retrieved account ?
A far simpler answer is simply to turn off the global sync enabled flag and then turn it back on. Android starts a full sync by defualt in this case.
See ContentResolver.setMasterSyncAutomatically().
Your app will need appropriate permissions in the manifest to be allowed to change that flag.

Howto let a user change account data in 'Accounts and sync'

There is an existing account on the phone that is used for a sync service. The account has some settings that the user entered when he created the account. Theses settings are stored as user data (--> mAccountManager.addAccountExplicitly(account, mPassword, userData)).
The user should be able to change these settings. How can this be achieved? Do I need a standalone app to change existing account data?
I guess the user would go to 'Settings'/'Accounts and sync'/'myAccount' and should find a menu entry like 'modify account data'. This menu entry should open the same activity that the user has already used to enter the data initially.
Any hints to push me in the right direction?
This fooled me for a while too - I expected to find getUserData()/setUserData() methods on the Account class, but they are on the AccountManager instead:
AccountManager am = AccountManager.get(context);
String myData = am.getUserData(account, SomeClass.MY_DATA_KEY);
myData = "Some New Value";
am.setUserData(account, SomeClass.MY_DATA_KEY, myData);
Check out the AccountManager setUserData method docs for more information.
Cheers, Andrew.

Categories

Resources