本文整理匯總了Java中android.content.Context.getClass方法的典型用法代碼示例。如果您正苦於以下問題:Java Context.getClass方法的具體用法?Java Context.getClass怎麽用?Java Context.getClass使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.content.Context
的用法示例。
在下文中一共展示了Context.getClass方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: fixBaseContextImplOpsPackage
import android.content.Context; //導入方法依賴的package包/類
private void fixBaseContextImplOpsPackage(Context context) throws IllegalAccessException {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1 && context != null && !TextUtils.equals(context.getPackageName(), mHostContext.getPackageName())) {
Context baseContext = context;
Class clazz = baseContext.getClass();
Field mOpPackageName = FieldUtils.getDeclaredField(clazz, "mOpPackageName", true);
if (mOpPackageName != null) {
Object valueObj = mOpPackageName.get(baseContext);
if (valueObj instanceof String) {
String opPackageName = ((String) valueObj);
if (!TextUtils.equals(opPackageName, mHostContext.getPackageName())) {
mOpPackageName.set(baseContext, mHostContext.getPackageName());
Log.i(TAG, "fixBaseContextImplOpsPackage OK!Context=%s,", baseContext);
}
}
}
}
}
示例2: fixBaseContextImplContentResolverOpsPackage
import android.content.Context; //導入方法依賴的package包/類
private void fixBaseContextImplContentResolverOpsPackage(Context context) throws IllegalAccessException {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1 && context != null && !TextUtils.equals(context.getPackageName(), mHostContext.getPackageName())) {
Context baseContext = context;
Class clazz = baseContext.getClass();
Field mContentResolver = FieldUtils.getDeclaredField(clazz, "mContentResolver", true);
if (mContentResolver != null) {
Object valueObj = mContentResolver.get(baseContext);
if (valueObj instanceof ContentResolver) {
ContentResolver contentResolver = ((ContentResolver) valueObj);
Field mPackageName = FieldUtils.getDeclaredField(ContentResolver.class, "mPackageName", true);
Object mPackageNameValueObj = mPackageName.get(contentResolver);
if (mPackageNameValueObj != null && mPackageNameValueObj instanceof String) {
String packageName = ((String) mPackageNameValueObj);
if (!TextUtils.equals(packageName, mHostContext.getPackageName())) {
mPackageName.set(contentResolver, mHostContext.getPackageName());
Log.i(TAG, "fixBaseContextImplContentResolverOpsPackage OK!Context=%s,contentResolver=%s", baseContext, contentResolver);
}
}
}
}
}
}
示例3: getVersionName
import android.content.Context; //導入方法依賴的package包/類
public static String getVersionName(Context context) {
try {
ComponentName comp = new ComponentName(context, context.getClass());
PackageInfo pinfo = context.getPackageManager().getPackageInfo(comp.getPackageName(), 0);
return pinfo.versionName;
} catch (android.content.pm.PackageManager.NameNotFoundException e) {
return null;
}
}
示例4: getVersionName
import android.content.Context; //導入方法依賴的package包/類
static String getVersionName(Context context) {
try {
ComponentName comp = new ComponentName(context, context.getClass());
PackageInfo pinfo = context.getPackageManager().getPackageInfo(comp.getPackageName(), 0);
return pinfo.versionName;
} catch (android.content.pm.PackageManager.NameNotFoundException e) {
return null;
}
}