问题描述
这是源$ C $ C ...
This is the source code...
public class GetAppList extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
try {
List<PackageInfo> appListInfo = this.getPackageManager()
.getInstalledPackages(0);
JSONArray ja = new JSONArray();
for (PackageInfo p : appListInfo) {
if (p.applicationInfo.uid > 10000) {
JSONObject jo = new JSONObject();
jo.put("label", p.applicationInfo.name);
jo.put("packageName", p.applicationInfo.packageName);
ja.put(jo);
}
}
System.out.println(ja);
} catch (Exception e) {
// TODO: handle exception
}
}
}
这是结果〜
[{"packageName":"com.android.soundrecorder"},{"packageName":"com.android.alarmclock"},{"packageName":"com.android.sdksetup"},{"packageName":"com.android.launcher"},{"packageName":"com.google.android.providers.enhancedgooglesearch"},{"packageName":"com.gameloft.android.ANMP.GloftAsphalt5.asphalt5"},{"packageName":"com.android.contacts"},{"packageName":"com.zhang7nan.android"},{"packageName":"com.android.inputmethod.latin"},{"packageName":"irdc.ex03_19"},{"packageName":"com.android.calculator2"},{"packageName":"com.zhang7nan.getAppList"},{"packageName":"com.android.htmlviewer"},{"packageName":"com.androidbook.layout"},{"packageName":"irdc.EX05_04"},{"packageName":"com.android.browser"},{"packageName":"com.android.customlocale"},{"packageName":"com.android.music"},{"packageName":"com.android.netspeed"},{"packageName":"com.android.providers.userdictionary"},{"packageName":"com.android.inputmethod.pinyin"},{"packageName":"android.tts"},{"packageName":"com.android.providers.media"},{"packageName":"com.android.globalsearch"},{"packageName":"com.wd.AndroidDaemon"},{"packageName":"com.android.fallback"},{"packageName":"com.gameloft.android.GAND.GloftBia2.bia2"},{"packageName":"com.android.gesture.builder"},{"packageName":"org.lee.android"},{"packageName":"android.tether"},{"packageName":"com.android.providers.contacts"},{"packageName":"com.android.providers.applications"},{"packageName":"com.android.providers.drm"},{"packageName":"com.android.term"},{"packageName":"com.android.development"},{"packageName":"com.android.packageinstaller"},{"packageName":"com.svox.pico"},{"packageName":"com.android.camera"},{"packageName":"jp.co.omronsoft.openwnn"},{"packageName":"com.android.email"},{"packageName":"com.wandoujia.wandouapp"},{"packageName":"com.android.spare_parts"},{"packageName":"com.android.providers.downloads"}]
[{"packageName":"com.android.soundrecorder"},{"packageName":"com.android.alarmclock"},{"packageName":"com.android.sdksetup"},{"packageName":"com.android.launcher"},{"packageName":"com.google.android.providers.enhancedgooglesearch"},{"packageName":"com.gameloft.android.ANMP.GloftAsphalt5.asphalt5"},{"packageName":"com.android.contacts"},{"packageName":"com.zhang7nan.android"},{"packageName":"com.android.inputmethod.latin"},{"packageName":"irdc.ex03_19"},{"packageName":"com.android.calculator2"},{"packageName":"com.zhang7nan.getAppList"},{"packageName":"com.android.htmlviewer"},{"packageName":"com.androidbook.layout"},{"packageName":"irdc.EX05_04"},{"packageName":"com.android.browser"},{"packageName":"com.android.customlocale"},{"packageName":"com.android.music"},{"packageName":"com.android.netspeed"},{"packageName":"com.android.providers.userdictionary"},{"packageName":"com.android.inputmethod.pinyin"},{"packageName":"android.tts"},{"packageName":"com.android.providers.media"},{"packageName":"com.android.globalsearch"},{"packageName":"com.wd.AndroidDaemon"},{"packageName":"com.android.fallback"},{"packageName":"com.gameloft.android.GAND.GloftBia2.bia2"},{"packageName":"com.android.gesture.builder"},{"packageName":"org.lee.android"},{"packageName":"android.tether"},{"packageName":"com.android.providers.contacts"},{"packageName":"com.android.providers.applications"},{"packageName":"com.android.providers.drm"},{"packageName":"com.android.term"},{"packageName":"com.android.development"},{"packageName":"com.android.packageinstaller"},{"packageName":"com.svox.pico"},{"packageName":"com.android.camera"},{"packageName":"jp.co.omronsoft.openwnn"},{"packageName":"com.android.email"},{"packageName":"com.wandoujia.wandouapp"},{"packageName":"com.android.spare_parts"},{"packageName":"com.android.providers.downloads"}]
应用程序名称不存在!求救!
app name does not exist!help!
推荐答案
下面是一个片段说明你想做什么:
Here's a snippet illustrating what you want to do:
public InstalledPackage(PackageManager pm, ApplicationInfo ai, Drawable defaultIcon) {
name = ai.packageName;
icon = defaultIcon;
pkg = ai.packageName;
if (ai.labelRes != 0) {
name = (String) pm.getText(ai.packageName, ai.labelRes, ai);
}
if (ai.icon != 0) {
icon = pm.getDrawable(ai.packageName, ai.icon, ai);
}
}
请记住很多的包不会有一个标签。
Keep in mind many packages won't have a label.
这篇关于如何获得在Android中安装的应用程序列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!