当前位置: 首页>>代码示例>>Java>>正文


Java Context.getPackageManager方法代码示例

本文整理汇总了Java中android.content.Context.getPackageManager方法的典型用法代码示例。如果您正苦于以下问题:Java Context.getPackageManager方法的具体用法?Java Context.getPackageManager怎么用?Java Context.getPackageManager使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.content.Context的用法示例。


在下文中一共展示了Context.getPackageManager方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getAPKVersionInfo

import android.content.Context; //导入方法依赖的package包/类
public static PackageInfo getAPKVersionInfo(Context context,
                                            String packageName) {
    PackageManager packageManager = context.getPackageManager();
    PackageInfo packInfo = null;
    try {
        packInfo = packageManager.getPackageInfo(packageName, 0);
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
    return packInfo;
}
 
开发者ID:TAnsz,项目名称:MyTvLauncher,代码行数:12,代码来源:Tools.java

示例2: getPermissionInfo

import android.content.Context; //导入方法依赖的package包/类
/**
 * Returns information string about permission
 **/
@Nullable
private static String getPermissionInfo(@NonNull Context context, @NonNull String permission) {
    context = context.getApplicationContext();
    PackageManager pm = context.getPackageManager();
    PermissionInfo info = null;
    try {
        info = pm.getPermissionInfo(permission, PackageManager.GET_META_DATA);
    } catch (PackageManager.NameNotFoundException ex) {
        Log.w(TAG, ex);
    }

    if (info != null) {
        CharSequence label = info.loadLabel(pm);
        if (label == null) {
            label = info.nonLocalizedLabel;
        }
        return label.toString();
    }

    return null;
}
 
开发者ID:kaliturin,项目名称:BlackList,代码行数:25,代码来源:Permissions.java

示例3: getApkPublicKey

import android.content.Context; //导入方法依赖的package包/类
/**
 * 获得当前安装apk的公钥
 *
 * @param context Context
 * @return 公钥
 */
private static PublicKey getApkPublicKey(Context context) {
    if (context == null) {
        return null;
    }
    try {
        PackageManager pm = context.getPackageManager();
        String packageName = context.getPackageName();
        PackageInfo packageInfo = pm.getPackageInfo(packageName,
                PackageManager.GET_SIGNATURES);
        CertificateFactory certFactory = CertificateFactory
                .getInstance("X.509");
        ByteArrayInputStream stream = new ByteArrayInputStream(
                packageInfo.signatures[0].toByteArray());
        X509Certificate cert = (X509Certificate) certFactory
                .generateCertificate(stream);
        PublicKey publicKey = cert.getPublicKey();
        return publicKey;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
 
开发者ID:lizhangqu,项目名称:CorePatch,代码行数:29,代码来源:SignatureVerify.java

示例4: getVersionCode

import android.content.Context; //导入方法依赖的package包/类
/**
 * @return 当前程序的版本号
 */
public static int getVersionCode(Context context) {
	int version;
	try {
		PackageManager pm = context.getPackageManager();
		PackageInfo packageInfo = pm.getPackageInfo(context.getPackageName(), 0);
		version = packageInfo.versionCode;
	} catch (Exception e) {
		e.printStackTrace();
		version = 0;
	}
	return version;
}
 
开发者ID:Catslovetoplaygames,项目名称:MVP,代码行数:16,代码来源:ApkUtils.java

示例5: getPackageInfo

import android.content.Context; //导入方法依赖的package包/类
public static PackageInfo getPackageInfo(Context context, String appUri) {
    try {
        PackageManager pm = context.getPackageManager();
        return pm.getPackageInfo(appUri, PackageManager.GET_ACTIVITIES);
    } catch (Exception e) {
        return null;
    }
}
 
开发者ID:WrBug,项目名称:GravityBox,代码行数:9,代码来源:Utils.java

示例6: hasQQClientAvailable

import android.content.Context; //导入方法依赖的package包/类
/**
 * 判断 用户是否安装QQ客户端
 */
public static boolean hasQQClientAvailable(Context context) {
    final PackageManager packageManager = context.getPackageManager();
    List<PackageInfo> pinfo = packageManager.getInstalledPackages(0);
    if (pinfo != null) {
        for (int i = 0; i < pinfo.size(); i++) {
            String pn = pinfo.get(i).packageName;
            LogUtils.e("pn = " + pn);
            if (pn.equalsIgnoreCase("com.tencent.qqlite") || pn.equalsIgnoreCase("com.tencent.mobileqq")) {
                return true;
            }
        }
    }
    return false;
}
 
开发者ID:paterWang,项目名称:EasyReader,代码行数:18,代码来源:FeedbackActivity.java

示例7: isAppDebug

import android.content.Context; //导入方法依赖的package包/类
/**
 * 判断App是否是Debug版本
 *
 * @param context     上下文
 * @param packageName 包名
 * @return {@code true}: 是<br>{@code false}: 否
 */
public static boolean isAppDebug(Context context, String packageName) {
    if (StringCovertUtils.isSpace(packageName)) return false;
    try {
        PackageManager pm = context.getPackageManager();
        ApplicationInfo ai = pm.getApplicationInfo(packageName, 0);
        return ai != null && (ai.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0;
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
        return false;
    }
}
 
开发者ID:tututututututu,项目名称:BaseCore,代码行数:19,代码来源:AppUtils.java

示例8: appVersionCode

import android.content.Context; //导入方法依赖的package包/类
public static String appVersionCode(Context context) {
    PackageManager pm = context.getPackageManager();
    PackageInfo pi = null;
    try {
        pi = pm.getPackageInfo(context.getPackageName(), PackageManager.GET_ACTIVITIES);
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
        return "unknown";
    }
    return pi.versionCode + "";
}
 
开发者ID:angcyo,项目名称:RLibrary,代码行数:12,代码来源:Device.java

示例9: getAppSignature

import android.content.Context; //导入方法依赖的package包/类
/**
 * 获取App签名
 *
 * @param context     上下文
 * @param packageName 包名
 * @return App签名
 */
@SuppressLint("PackageManagerGetSignatures")
public static Signature[] getAppSignature(Context context, String packageName) {
    if (StringCovertUtils.isSpace(packageName)) return null;
    try {
        PackageManager pm = context.getPackageManager();
        PackageInfo pi = pm.getPackageInfo(packageName, PackageManager.GET_SIGNATURES);
        return pi == null ? null : pi.signatures;
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
        return null;
    }
}
 
开发者ID:tututututututu,项目名称:BaseCore,代码行数:20,代码来源:AppUtils.java

示例10: onReceive

import android.content.Context; //导入方法依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
	if(SipManager.ACTION_GET_PHONE_HANDLERS.equals(intent.getAction())) {
		
		PendingIntent pendingIntent = null;
		String number = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
		// We must handle that clean way cause when call just to 
		// get the row in account list expect this to reply correctly
		if(number != null && PhoneCapabilityTester.isPhone(context)) {
			// Build pending intent
			Intent i = new Intent(Intent.ACTION_CALL);
			i.setData(Uri.fromParts("tel", number, null));
			pendingIntent = PendingIntent.getActivity(context, 0, i, 0);
		}
		
		// Retrieve and cache infos from the phone app 
		if(!sPhoneAppInfoLoaded) {
   			List<ResolveInfo> callers = PhoneCapabilityTester.resolveActivitiesForPriviledgedCall(context);
   			if(callers != null) {
   				for(final ResolveInfo caller : callers) {
   					if(caller.activityInfo.packageName.startsWith("com.android")) {
   						PackageManager pm = context.getPackageManager();
   						Resources remoteRes;
   						try {
   							// We load the resource in the context of the remote app to have a bitmap to return.
   						    remoteRes = pm.getResourcesForApplication(caller.activityInfo.applicationInfo);
   						    sPhoneAppBmp = BitmapFactory.decodeResource(remoteRes, caller.getIconResource());
   						} catch (NameNotFoundException e) {
   							Log.e(THIS_FILE, "Impossible to load ", e);
   						}
   						break;
   					}
   				}
   			}
   			sPhoneAppInfoLoaded = true;
		}
		
		
		//Build the result for the row (label, icon, pending intent, and excluded phone number)
		Bundle results = getResultExtras(true);
		if(pendingIntent != null) {
			results.putParcelable(CallHandlerPlugin.EXTRA_REMOTE_INTENT_TOKEN, pendingIntent);
		}
		results.putString(Intent.EXTRA_TITLE, context.getResources().getString(R.string.use_pstn));
		if(sPhoneAppBmp != null) {
			results.putParcelable(Intent.EXTRA_SHORTCUT_ICON, sPhoneAppBmp);
		}
		
		// This will exclude next time tel:xxx is raised from csipsimple treatment which is wanted
		results.putString(Intent.EXTRA_PHONE_NUMBER, number);
		
	}
}
 
开发者ID:treasure-lau,项目名称:CSipSimple,代码行数:54,代码来源:CallHandler.java

示例11: getIcon

import android.content.Context; //导入方法依赖的package包/类
private int getIcon(Context context){

            final PackageManager packageManager = context.getPackageManager();
            ApplicationInfo appInfo = null;
            try {
                appInfo = packageManager.getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA);
            } catch (PackageManager.NameNotFoundException e) {
                e.printStackTrace();
            }
            if (appInfo != null){
                return appInfo.icon;
            }
            return 0;
        }
 
开发者ID:androidstarjack,项目名称:ServiceDownLoadApp-master,代码行数:15,代码来源:UpdateService.java

示例12: getVersionCode

import android.content.Context; //导入方法依赖的package包/类
/**
 * 返回版本号
 * 对应build.gradle中的versionCode
 *
 * @param context
 * @return
 */
public static String getVersionCode(Context context) {
    String versionCode = "";
    try {
        PackageManager packageManager = context.getPackageManager();
        PackageInfo packInfo = packageManager.getPackageInfo(context.getPackageName(), 0);
        versionCode = String.valueOf(packInfo.versionCode);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return versionCode;
}
 
开发者ID:w568w,项目名称:fuckView,代码行数:19,代码来源:PreferencesActivity.java

示例13: hasCamera

import android.content.Context; //导入方法依赖的package包/类
public static final boolean hasCamera(Context context) {
    if (sHasCamera == null) {
        PackageManager pckMgr = context.getPackageManager();
        boolean flag = pckMgr
                .hasSystemFeature("android.hardware.camera.front");
        boolean flag1 = pckMgr.hasSystemFeature("android.hardware.camera");
        boolean flag2;
        flag2 = flag || flag1;
        sHasCamera = flag2;
    }
    return sHasCamera;
}
 
开发者ID:QMUI,项目名称:QMUI_Android,代码行数:13,代码来源:QMUIDisplayHelper.java

示例14: getAppVersionName

import android.content.Context; //导入方法依赖的package包/类
/**
 * 获取应用版本号
 *
 * @param context
 * @return
 */
public static String getAppVersionName(Context context) {
    PackageManager packageManager = context.getPackageManager();
    String versionName = "0.00";
    try {
        PackageInfo packageInfo = packageManager.getPackageInfo(
                context.getPackageName(), 0);
        versionName = packageInfo.versionName;
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
    return versionName;
}
 
开发者ID:Liuzhiyang94,项目名称:ComponentProjectDemo,代码行数:19,代码来源:CommonUtils.java

示例15: getGMSVersionCode

import android.content.Context; //导入方法依赖的package包/类
@CalledByNative
public static String getGMSVersionCode(Context context) {
    String msg = "gms versionCode not available.";
    try {
        PackageManager packageManager = context.getPackageManager();
        PackageInfo packageInfo = packageManager.getPackageInfo("com.google.android.gms", 0);
        msg = Integer.toString(packageInfo.versionCode);
    } catch (NameNotFoundException e) {
        Log.d(TAG, "GMS package is not found: %s", e);
    }
    return msg;
}
 
开发者ID:lizhangqu,项目名称:chromium-net-for-android,代码行数:13,代码来源:BuildInfo.java


注:本文中的android.content.Context.getPackageManager方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。