这是源代码......
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”},{ “软件包名” : “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 “},{” 软件包名” : “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 “},{” 软件包名 “:” android.tts “},{” 软件包名 “:” com.android.providers.media “},{” 包ageName “:” 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”}]
应用名称不存在!帮助!
答案 0 :(得分:3)
以下是说明您要执行的操作的片段:
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);
}
}
请记住,许多包裹都没有标签。
答案 1 :(得分:0)
解决方案:
JSONArray ja = new JSONArray();
try {
HttpClient httpclient = new DefaultHttpClient();
HttpPost request = new HttpPost(sendDataUrl.toString());
List<NameValuePair> params = new ArrayList<NameValuePair>();
PackageManager pm = context.getPackageManager();
List<PackageInfo> appListInfo = pm.getInstalledPackages(0);
for (PackageInfo p : appListInfo) {
if (p.applicationInfo.uid > 10000) {
JSONObject jo = new JSONObject();
jo.put("label", p.applicationInfo.loadLabel(pm).toString());
jo.put("packageName", p.applicationInfo.packageName);
ja.put(jo);
}
}
谢谢你同性恋