问题描述
限时送ChatGPT账号..我正在构建一个 android 应用程序,我需要检查在设备中注册的每个帐户的同步设置.我知道我可以通过 ContentResolver 类来完成,但我遇到了一些问题.我设法获得了设备上所有帐户的列表,但我不知道在运行时从哪里获得特定帐户的相关权限.代码如下:
I am building an android app for which I need to check the sync setting of each individual account registered in the device. I know that I can do it through ContentResolver class but I am having some problem with it. I've managed to get the list of all accounts on the device but I don't know where to get the relevant authority of a specific account at run time. Below is the code:
AccountManager acm = AccountManager.get(getApplicationContext());
Account[] acct = acm.getAccounts();
for(int i=0;i<acct.length;i++){
int p = ContentResolver.getIsSyncable(acct[i], null);
Log.i(TAG,"account name is"+acct[i].name);
Log.i(TAG,"answer to syncable is: "+String.valueOf(p));
getIsSyncable(Account am,String authority) 要求提供帐户和权限.如您所见,我传入的是 NULL 而不是实际权限.有谁知道我可以找到相关帐户权限的方法吗?
The getIsSyncable(Account am,String authority) asks for an account and an authority. As you can see I am passing in NULL instead of the actual authority. Does anyone know of a way I can find the authority to the relevant account?
推荐答案
您可以检索已知的SyncAdapters,然后查询ContentResolver
You can retrieve the known SyncAdapters and then query the ContentResolver
AccountManager acm
= AccountManager.get(getApplicationContext());
Account[] acct = null;
SyncAdapterType[] types = ContentResolver.getSyncAdapterTypes();
for (SyncAdapterType type : types) {
Log.d(TAG, "--------------------");
Log.d(TAG, type.authority + "--" + type.accountType);
acct = acm.getAccountsByType(type.accountType);
for (int i = 0; i < acct.length; i++) {
int p = ContentResolver.getIsSyncable(acct[i], type.authority);
Log.i(TAG, "account name: " + acct[i].name);
Log.i(TAG, "syncable: " + String.valueOf(p));
}
}
输出:
11-15 17:12:51.899:调试/同步样本(4572):com.google.android.music.MusicContent--com.google 11-15 17:12:51.899:
11-15 17:12:51.899: DEBUG/syncsample(4572): com.google.android.music.MusicContent--com.google 11-15 17:12:51.899:
INFO/syncsample(4572):账户名:xxxxxxxxx@gmail 11-1517:12:51.899:信息/同步样本(4572):可同步:1 11-15 17:12:51.899:
INFO/syncsample(4572): account name: xxxxxxxxx@gmail 11-15 17:12:51.899: INFO/syncsample(4572): syncable: 1 11-15 17:12:51.899:
INFO/syncsample(4572):账户名:xxxxxx@google 11-1517:12:51.899:信息/同步样本(4572):可同步:0
INFO/syncsample(4572): account name: xxxxxx@google 11-15 17:12:51.899: INFO/syncsample(4572): syncable: 0
这篇关于如何检查android中的同步设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论