本文整理汇总了Java中android.content.pm.PackageManager.resolveContentProvider方法的典型用法代码示例。如果您正苦于以下问题:Java PackageManager.resolveContentProvider方法的具体用法?Java PackageManager.resolveContentProvider怎么用?Java PackageManager.resolveContentProvider使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.content.pm.PackageManager
的用法示例。
在下文中一共展示了PackageManager.resolveContentProvider方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: hasContentProvider
import android.content.pm.PackageManager; //导入方法依赖的package包/类
public static void hasContentProvider(Context context) {
Validate.notNull(context, "context");
String appId = Validate.hasAppID();
PackageManager pm = context.getPackageManager();
if (pm != null) {
String providerName = CONTENT_PROVIDER_BASE + appId;
if (pm.resolveContentProvider(providerName, 0) == null) {
throw new IllegalStateException(
String.format(CONTENT_PROVIDER_NOT_FOUND_REASON, providerName));
}
}
}
示例2: loadPackageIcon
import android.content.pm.PackageManager; //导入方法依赖的package包/类
public static Drawable loadPackageIcon(Context context, String authority, int icon) {
if (icon != 0) {
if (authority != null) {
final PackageManager pm = context.getPackageManager();
final ProviderInfo info = pm.resolveContentProvider(authority, 0);
if (info != null) {
return pm.getDrawable(info.packageName, icon, info.applicationInfo);
}
} else {
return ContextCompat.getDrawable(context, icon);
}
}
return null;
}
示例3: initIfNecessary
import android.content.pm.PackageManager; //导入方法依赖的package包/类
private boolean initIfNecessary() {
if ( !mInit ) {
Context ctx = getContext();
PackageManager pm = ctx.getPackageManager();
ProviderInfo pi = pm.resolveContentProvider(getAuthority(), PackageManager.GET_META_DATA);
PackageInfo packInfo;
try {
packInfo = pm.getPackageInfo(ctx.getPackageName(), 0);
} catch (NameNotFoundException e1) {
e1.printStackTrace();
return false;
}
int patchFileVersion;
int mainFileVersion;
int appVersionCode = packInfo.versionCode;
String[] resourceFiles = null;
if ( null != pi.metaData ) {
mainFileVersion = pi.metaData.getInt("mainVersion", appVersionCode);
patchFileVersion = pi.metaData.getInt("patchVersion", appVersionCode);
String mainFileName = pi.metaData.getString("mainFilename", NO_FILE);
if ( NO_FILE != mainFileName ) {
String patchFileName = pi.metaData.getString("patchFilename", NO_FILE);
if ( NO_FILE != patchFileName ) {
resourceFiles = new String[] { mainFileName, patchFileName };
} else {
resourceFiles = new String[] { mainFileName };
}
}
} else {
mainFileVersion = patchFileVersion = appVersionCode;
}
try {
if ( null == resourceFiles ) {
mAPKExtensionFile = APKExpansionSupport.getAPKExpansionZipFile(ctx, mainFileVersion, patchFileVersion);
} else {
mAPKExtensionFile = APKExpansionSupport.getResourceZipFile(resourceFiles);
}
mInit = true;
return true;
} catch (IOException e) {
e.printStackTrace();
}
}
return false;
}