本文整理汇总了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;
}
}