2011-04-14 115 views
13

有沒有一種方法,我可以得到應用程序名稱,應用程序版本和應用程序圖標時,該尚未安裝包? (關於SD卡的一些apk文件)獲取apk文件的圖標,版本,名稱

+0

做你能夠找到其它版本號,如果是的話,你能不能請發表您的答案。 – 2014-06-11 14:19:54

回答

6

我可以用getPackageArchiveInfo(archiveFilePath, flags)getApplicationIcon (ApplicationInfo info)得到APK圖標,版本,名稱

+6

對於未安裝:(應用程序不工作,只返回默認的應用程序圖標 – 2011-07-30 21:19:28

+1

正確答案的http://計算器。com/a/14313280/185022 – 2014-03-17 09:51:22

5
// Install a known apk file from the SD-Card 
// or launch it if installed. 
// -hsigmond 

protected void runAppFromApkFileOnSdCard() { 

     final PackageManager pm = getActivity().getPackageManager(); 
     String apkFileName  = "application_name.apk"; 
     String fullPath   = "/sdcard/"+apkFileName; 
     PackageInfo packageInfo = pm.getPackageArchiveInfo(fullPath, 0); 
     Intent intent   = pm.getLaunchIntentForPackage(packageInfo.packageName); 

     if(intent == null){ 
      File file = new File(fullPath); 
      intent  = new Intent(); 
      intent.setAction(Intent.ACTION_VIEW); 
      intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
      intent.setDataAndType(Uri.fromFile(file), 
      "application/vnd.android.package-archive"); 
     } 
     startActivity(intent); 
    } 

用途:

packageInfo.applicationInfo.['name','icon','logo'] etc. 

例圖標:

Drawable icon = packageInfo.applicationInfo.loadIcon(getActivity().getPackageManager()); 
+0

我試過這個,但是packageInfo總是爲空。我缺少任何權限? – 1HaKr 2011-06-11 13:14:12

+0

適用於Samsung Galaxy Tab 8.9,Android版本3.2。 packageInfo不爲null,如果應用程序尚未安裝,intent爲null。 – giacatho 2012-07-05 02:39:37

13

我曾嘗試:

PackageInfo info = getPackageManager().getPackageArchiveInfo(fullPath, 0); 
ApplicationInfo appinfo = info.applicationInfo; 
label = getPackageManager().getApplicationLabel(appinfo).toString(); 
img = getPackageManager().getApplicationIcon(info.packageName); 

但如果apk未installated不行這段代碼

0

正如你可能已經發現了,如果安裝了應用程序PackageManager只會對你有用。

爲了解決您的獲取信息,而無需安裝應用程序使用APK提取的問題,請參見:http://code.google.com/p/apk-extractor/downloads/detail?name=APK-Extractor-src-1.0.zip&can=2&q=

該項目是建立一個公開可用的解析器 可以解析Android的二進制XML的嘗試。 AAPT(Android的資產包裝 工具)編碼/谷歌的專有二進制 XML格式解碼XML資源。這是一個普遍認爲,這是一個通用的WBXML格式 任何WBXML能夠解析器可以解析它。但是這是錯誤的。

如果您打算探索Android的二進制XML,我的代碼庫 可以幫助您在其上開始並構建服務。

版本1.0-能夠解析Android Manifest,XML佈局等。 並將DEX/ODEX轉換爲CLASS,可以通過任何 反編譯器打開。

他的博客是在這裏: http://prasanta-paul.blogspot.com/2012/03/android-apk-extractor.html

53

我只花了更多的時間比我將永遠不會承認尋找解決這一..並找到了! :) :)

遊蕩到這個引用後: http://code.google.com/p/android/issues/detail?id=9151 我發現了竅門獲取圖標和名稱(標籤,這是)從尚未安裝的apk文件。

我希望這不是爲時已晚,以幫助他人與此:

String APKFilePath = "mnt/sdcard/myapkfile.apk"; //For example... 
PackageManager pm = getPackageManager(); 
PackageInfo pi = pm.getPackageArchiveInfo(APKFilePath, 0); 

// the secret are these two lines.... 
pi.applicationInfo.sourceDir  = APKFilePath; 
pi.applicationInfo.publicSourceDir = APKFilePath; 
// 

Drawable APKicon = pi.applicationInfo.loadIcon(pm); 
String AppName = (String)pi.applicationInfo.loadLabel(pm); 

後光測試這一點,似乎工作...噢。

+0

太棒了,它的工作原理! – lorenzoff 2013-02-07 22:17:37

+0

酷!這個對我有用。謝謝。 – posaidong 2013-09-02 03:36:30

+0

必須必須是正確的市場答案:D幫助了很多謝謝:) – 2014-03-17 09:50:14