本文整理匯總了Java中android.content.pm.PackageManager.getPackageInfo方法的典型用法代碼示例。如果您正苦於以下問題:Java PackageManager.getPackageInfo方法的具體用法?Java PackageManager.getPackageInfo怎麽用?Java PackageManager.getPackageInfo使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.content.pm.PackageManager
的用法示例。
在下文中一共展示了PackageManager.getPackageInfo方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getAppVersion
import android.content.pm.PackageManager; //導入方法依賴的package包/類
/**
* manifest 中的 versionName 字段
*/
public static String getAppVersion(Context context) {
if (appVersionName == null) {
PackageManager manager = context.getPackageManager();
try {
android.content.pm.PackageInfo info = manager.getPackageInfo(context.getPackageName(), 0);
appVersionName = info.versionName;
} catch (Exception e) {
e.printStackTrace();
}
}
if (appVersionName == null) {
return "";
} else {
return appVersionName;
}
}
示例2: getAppVersion
import android.content.pm.PackageManager; //導入方法依賴的package包/類
/**
* 返回版本信息
*
* @param context
* @return
*/
public static String getAppVersion(Context context)
{
PackageManager localPackageManager = context.getPackageManager();
try
{
String str = localPackageManager.getPackageInfo(context.getPackageName(), 0).versionName;
return str;
}
catch (PackageManager.NameNotFoundException e)
{
Log.E(TAG, "getAppVersion error" + e.getMessage());
e.printStackTrace();
}
return "";
}
示例3: getFingerprint
import android.content.pm.PackageManager; //導入方法依賴的package包/類
/**
* Gets the fingerprint of the signed certificate of a package.
*/
public static String getFingerprint(Context context, String packageName) throws Exception {
PackageManager pm = context.getPackageManager();
PackageInfo packageInfo = pm.getPackageInfo(packageName, PackageManager.GET_SIGNATURES);
Signature[] signatures = packageInfo.signatures;
if (signatures.length != 1) {
throw new SecurityException(packageName + " has " + signatures.length + " signatures");
}
byte[] cert = signatures[0].toByteArray();
try (InputStream input = new ByteArrayInputStream(cert)) {
CertificateFactory factory = CertificateFactory.getInstance("X509");
X509Certificate x509 = (X509Certificate) factory.generateCertificate(input);
MessageDigest md = MessageDigest.getInstance("SHA256");
byte[] publicKey = md.digest(x509.getEncoded());
return toHexFormat(publicKey);
}
}
示例4: onCreate
import android.content.pm.PackageManager; //導入方法依賴的package包/類
public void onCreate(Context context) {
AttributeCache.init(context);
PackageManager pm = context.getPackageManager();
PackageInfo packageInfo = null;
try {
packageInfo = pm.getPackageInfo(context.getPackageName(),
PackageManager.GET_ACTIVITIES | PackageManager.GET_PROVIDERS | PackageManager.GET_META_DATA);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
if (packageInfo == null) {
throw new RuntimeException("Unable to found PackageInfo : " + context.getPackageName());
}
sService.set(this);
}
示例5: dumpPhoneInfo
import android.content.pm.PackageManager; //導入方法依賴的package包/類
@SuppressWarnings("deprecation")
private void dumpPhoneInfo(PrintWriter pw) throws PackageManager.NameNotFoundException {
PackageManager pm = mContext.getPackageManager();
PackageInfo pi = pm.getPackageInfo(mContext.getPackageName(),
PackageManager.GET_ACTIVITIES);
pw.print("App Version: ");
pw.print(pi.versionName);
pw.print('_');
pw.println(pi.versionCode);
/* Android 版本號 */
pw.print("OS Version: ");
pw.print(Build.VERSION.RELEASE);
pw.print('_');
pw.println(SDK_INT);
/* 手機製造商 */
pw.print("Vendor: ");
pw.println(Build.MODEL);
/* CPU 架構 */
pw.print("CPU ABI: ");
pw.println(Build.CPU_ABI);
}
示例6: getAppVersionName
import android.content.pm.PackageManager; //導入方法依賴的package包/類
/**
* 返回app的版本名稱.
*
* @param context the context
* @return app version name
*/
public static String getAppVersionName(Context context) {
String version = "unknown";
// 獲取package manager的實例
PackageManager packageManager = context.getPackageManager();
// getPackageName()是你當前類的包名,0代表是獲取版本信息
PackageInfo packInfo;
try {
packInfo = packageManager.getPackageInfo(context.getPackageName(),
0);
version = packInfo.versionName;
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
// Log.i("版本名稱:", version);
return version;
}
示例7: getVersionCode
import android.content.pm.PackageManager; //導入方法依賴的package包/類
/**
* 獲取應用的versionCode
*
* @return int類型的versionCode
*/
public static int getVersionCode(Context context) {
try {
PackageManager manager = context.getPackageManager();
PackageInfo info = manager.getPackageInfo(context.getPackageName(), 0);
return info.versionCode;
} catch (Exception e) {
e.printStackTrace();
return 0;
}
}
示例8: getAppInfo
import android.content.pm.PackageManager; //導入方法依賴的package包/類
/**
* 獲取當前App信息
* <p>AppInfo(名稱,圖標,包名,版本號,版本Code,是否安裝在SD卡,是否是用戶程序)
*/
public static AppInfo getAppInfo(Context context) {
PackageManager pm = context.getPackageManager();
PackageInfo pi = null;
try {
pi = pm.getPackageInfo(context.getApplicationContext().getPackageName(), 0);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
return pi != null ? getBean(pm, pi) : null;
}
示例9: getAppPath
import android.content.pm.PackageManager; //導入方法依賴的package包/類
/**
* 獲取App路徑
*
* @param packageName 包名
* @return App路徑
*/
public static String getAppPath(final String packageName) {
if (isSpace(packageName)) return null;
try {
PackageManager pm = Utils.getApp().getPackageManager();
PackageInfo pi = pm.getPackageInfo(packageName, 0);
return pi == null ? null : pi.applicationInfo.sourceDir;
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
return null;
}
}
示例10: getAppVersionCode
import android.content.pm.PackageManager; //導入方法依賴的package包/類
/**
* 獲取版本號
*/
public static int getAppVersionCode(Context context) {
int versioncode = -1;
try {
// ---get the package info---
PackageManager pm = context.getPackageManager();
PackageInfo pi = pm.getPackageInfo(context.getPackageName(), 0);
versioncode = pi.versionCode;
} catch (Exception e) {
Log.e("VersionInfo", "Exception", e);
}
return versioncode;
}
示例11: check
import android.content.pm.PackageManager; //導入方法依賴的package包/類
/**
* Check package is support MiPush.
* @param pkg Package Name
* @param manager Package manager
* @return This package support status. If not use MiPush, will returns null
*/
@Nullable
public static SupportStatus check (String pkg,
PackageManager manager) {
try {
PackageInfo info = manager.getPackageInfo(pkg, PackageManager.GET_SERVICES |
PackageManager.GET_RECEIVERS | PackageManager.GET_DISABLED_COMPONENTS);
return check(info, manager);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
return null;
}
}
示例12: getAppVersionName
import android.content.pm.PackageManager; //導入方法依賴的package包/類
/**
* 獲取App版本號
*
* @param context 上下文
* @param packageName 包名
* @return App版本號
*/
public static String getAppVersionName(Context context, String packageName) {
if (StringCovertUtils.isSpace(packageName)) return null;
try {
PackageManager pm = context.getPackageManager();
PackageInfo pi = pm.getPackageInfo(packageName, 0);
return pi == null ? null : pi.versionName;
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
return null;
}
}
示例13: getVersionCode
import android.content.pm.PackageManager; //導入方法依賴的package包/類
/**
* 根據包名獲取程序的VersionCode
*
* @param pContext
* @param pPackageName
* @return
*/
public static final int getVersionCode(Context pContext, String pPackageName) {
PackageManager packageManager = pContext.getPackageManager();
PackageInfo packageInfo = null;
try {
packageInfo = packageManager.getPackageInfo(pPackageName, 0);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
if (packageInfo != null) {
return packageInfo.versionCode;
} else {
return UNKNOWN_VERSION_CODE;
}
}
示例14: getApplicationIconDrawable
import android.content.pm.PackageManager; //導入方法依賴的package包/類
/**
* 獲取應用啟動圖標
* @param context
* @return
* @throws Exception
*/
public static Drawable getApplicationIconDrawable(Context context) throws Exception {
PackageManager pm = context.getPackageManager();
String packageName = getTopActivityPackageName(context);
PackageInfo packageInfo = pm.getPackageInfo(packageName, PackageManager.GET_UNINSTALLED_PACKAGES);
Drawable drawable = packageInfo.applicationInfo.loadIcon(pm);
return drawable;
}
示例15: getAppName
import android.content.pm.PackageManager; //導入方法依賴的package包/類
/**
* 獲取App名稱
*
* @param context 上下文
* @param packageName 包名
* @return App名稱
*/
public static String getAppName(Context context, String packageName) {
if (DataUtil.isNullString(packageName))
return null;
try {
PackageManager pm = context.getPackageManager();
PackageInfo pi = pm.getPackageInfo(packageName, 0);
return pi == null ? null : pi.applicationInfo.loadLabel(pm).toString();
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
return null;
}
}