对于APK文件
PackageManager mPackageManager = getPackageManager(); PackageInfo p = mPackageManager.getPackageArchiveInfo(<file path>, 0); if (p != null) { ApplicationInfo appInfo = p.applicationInfo; String appname = mPackageManager.getApplicationLabel(appInfo) .toString(); String packageName = p.packageName; String versionName = p.versionName; Drawable icon = mPackageManager.getApplicationIcon(appInfo); }
对于已安装的程序
// get all installed application PackageManager mPackageManager = getPackageManager(); List<PackageInfo> packs = mPackageManager.getInstalledPackages(0); int size = packs.size(); for (int i = 0; i < size; i++) { PackageInfo p = packs.get(i); if (p.applicationInfo.sourceDir.startsWith("/system/app")) { // ignore system application continue; } // get application detail ApplicationInfo appInfo = p.applicationInfo; String appname = mPackageManager.getApplicationLabel(appInfo) .toString(); String packageName = p.packageName; String versionName = p.versionName; Drawable icon = mPackageManager.getApplicationIcon(appInfo); }
mPackageManager.getApplicationIcon(appInfo);
这种对于没有安装的,apk文件是不行的。
没安装的apk文件,只能得到resId,不能得到值。
(比如label icon applicationname等,都只能得到resid,得不到值)
有其他什么办法吗?
mPackageManager.getApplicationIcon(appInfo);
这种对于没有安装的,apk文件是不行的。
没安装的apk文件,只能得到resId,不能得到值。
(比如label icon applicationname等,都只能得到resid,得不到值)
有其他什么办法吗?
SDK1.6上应该是正确的啊,你在SDK是多少?
/res/values/style.xml
<resources>
<style name="Transparent">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowAnimationStyle">@android:style/Animation.Translucent</item>
<item name ="android:windowBackground">@color/transparent</item>
<item name="android:windowNoTitle">true</item>
<item name="android:colorForeground">#fff</item>
</style>
</resources>
<color name="transparent">#00000000</color>
<activity android:name="MyActivity" android:theme="@style/Transparent"></activity>
private void updateResultsInUi() {
TextView jpgName = (TextView)findViewById(R.id.jpgname);
ImageView jpgView = (ImageView)findViewById(R.id.jpgview);
String myJpgPath = "/sdcard/test.jpg";
jpgName.setText(myJpgPath);
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 2;
Bitmap bm = BitmapFactory.decodeFile(myJpgPath, options);
jpgView.setImageBitmap(bm);
}
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); this.pd = ProgressDialog.show(this, "Working...", "*** Downloading Data...", true, false); new DownloadTask().execute(" parameters needed for download"); } private class DownloadTask extends AsyncTask<String, Void, Object> { protected Void doInBackground(String... args) { Log.d("********Jorgesys", "Background thread starting......"); startLongRunningOperation(); return null; } protected void onPostExecute(Object result) { Log.d("********Jorgesys", "onPostExecute......"); if (Splash.this.pd != null) { Splash.this.pd.dismiss(); } updateResultsInUi(); } } protected void startLongRunningOperation() { try { ftp = new FTPClient(); ftp.connect(host); ftp.login("username", "password"); ftp.changeDirectory("public_ftp"); ftp.download("test.jpg", new java.io.File("/sdcard/test.jpg")); } catch(Exception e) { } }