您好,登錄后才能下訂單哦!
一、獲取APK圖標
public static Drawable getApkIcon(Context context, String apkPath) { PackageManager pm = context.getPackageManager(); PackageInfo info = pm.getPackageArchiveInfo(apkPath, PackageManager.GET_ACTIVITIES); if (info != null) { ApplicationInfo appInfo = info.applicationInfo; appInfo.sourceDir = apkPath; appInfo.publicSourceDir = apkPath; try { return appInfo.loadIcon(pm); } catch (OutOfMemoryError e) { Log.e("ApkIconLoader", e.toString()); } } return null; }
下面代碼段中PackageManager、PackageInfo、ApplicationInfo均同上面一致。
二、獲取APK名稱
String label = appInfo.loadLabel(mPackManager).toString();
三、獲取APK包名
String packageName = appInfo.packageName;
四、獲取APK版本號
String version = info.versionName==null?<p ></p><p >"0":info.versionName</p>
五、推斷APK是否安裝
private boolean isApkInstalled(String packagename) { PackageManager localPackageManager = getPackageManager(); try { PackageInfo localPackageInfo = localPackageManager.getPackageInfo(packagename, PackageManager.GET_UNINSTALLED_PACKAGES); return true; } catch (PackageManager.NameNotFoundException localNameNotFoundException) { return false; } }
六、安裝APK
private void installAPK(String apkPath) { Intent intent = new Intent(); intent.setAction(Intent.ACTION_VIEW); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setDataAndType(Uri.parse("file://" + apkPath), "application/vnd.android.package-archive"); mContext.startActivity(intent); }
七、打開APK
private void openAPK(String packagename) { PackageManager packageManager = mContext.getPackageManager(); Intent intent=new Intent(); intent =packageManager.getLaunchIntentForPackage(packagename); mContext.startActivity(intent); }
以上這篇Android 獲取未安裝的APK圖標、版本號、包名等信息方法就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持億速云。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。