當前位置: 首頁>>代碼示例>>Java>>正文


Java Context.getClass方法代碼示例

本文整理匯總了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);
                }
            }
        }
    }
}
 
開發者ID:amikey,項目名稱:DroidPlugin,代碼行數:18,代碼來源:PluginInstrumentation.java

示例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);
                    }
                }

            }
        }
    }
}
 
開發者ID:amikey,項目名稱:DroidPlugin,代碼行數:24,代碼來源:PluginInstrumentation.java

示例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;
    }
}
 
開發者ID:marcelohanel,項目名稱:PokerBankroll,代碼行數:10,代碼來源:Funcoes.java

示例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;
    }
}
 
開發者ID:marcelohanel,項目名稱:MaosPoker,代碼行數:10,代碼來源:Funcoes.java


注:本文中的android.content.Context.getClass方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。