实际上很简单,我只是把整个事情搞错了,试图从同步适配器中找出包,而一个包的所有组件都在它的 PackageInfo 中定义!
下面的代码会发现所有包提供者都是给定包(pkg_name)的同步适配器:
SyncAdapterType[] types = ContentResolver.getSyncAdapterTypes();
int J = types.length;
PackageInfo pi = pm.getPackageInfo(pkg_name, PackageManager.GET_PROVIDERS);
if (pi.providers != null)
{
int I = pi.providers.length;
for(int i = 0; i < I; i++)
{
ProviderInfo p = pi.providers[i];
for(int j = 0; j < J; j++)
{
SyncAdapterType sat = types[j];
if (p.authority.equals(sat.authority))
{
// This provider is a sync adapter
上面的代码需要特定的权限:
<uses-permission android:name="android.permission.READ_SYNC_SETTINGS" />