本文整理匯總了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;
}