本文整理匯總了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;
}