本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
}
示例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;
}
示例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;
}
}
示例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 + "";
}
示例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;
}
}
示例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);
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}