我正在尝试将所有已安装的应用程序列表(包名称)放入 Android 中的 JSONArray 中。Arrar 没有得到所有的应用程序,并且被 com 截断。
这是我正在使用的代码:
//get apps list from phone and populate <br>
final PackageManager packageManager = getPackageManager(); <br>
//get a list of installed apps. <br>
List<ApplicationInfo> installedApplications = packageManager.getInstalledApplications(PackageManager.GET_META_DATA); <br>
int count= 0; <br>
JSONArray jarr_appname = new JSONArray(); <br>
JSONArray jarr_packagename = new JSONArray(); <br>
for (ApplicationInfo appInfo : installedApplications) { <br>
jarr_appname.put(appInfo.loadLabel(packageManager)); <br>
Log.d("OUTPUT", "Package name : " + appInfo.packageName); <br>
jarr_packagename.put(appInfo.packageName); <br>
Log.d("OUTPUT", "Name: " + appInfo.loadLabel(packageManager)); <br>
count += 1; <br>
System.out.println("Total Apps count " + count); <br>
} <br>
System.out.println("App Name in json array" + jarr_appname); <br>
System.out.println("Package Name in json array" + jarr_packagename); <br>
输出 :
07-22 15:05:09.566: I/System.out(17395): Total Apps count 173
07-22 15:05:09.566: I/System.out(17395): App Name in json array["Stick Tennis","BBC Media",/* all remaining*/, "My Network"]
07-22 15:05:09.566: I/System.out(17395): Package Name in json array["air.com.sticksports.sticktennis","air.uk.co,bbc.android.mediaplayer",/* all remaining*/, "com.paypal.android.p2mobile","com
请注意“json 数组中的包名称”中的最后一个包名称以“com”开头,之后就没有其他内容了。谁能告诉我我是否遗漏了什么?
谢谢