How to get all apps installed on android phone(如何在安卓手机上安装所有应用程序)
问题描述
这是我目前拥有的代码,但我仍然无法获得手机上所有应用程序的列表.有谁看到我做错了什么?
This is the code that i have at the moment but i still can't get a list of all the apps on the phone. Does anyone see what i am doing wrong?
public class GetAppList extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
try {
List<PackageInfo> appListInfo1 = this.getPackageManager()
.getInstalledPackages(0);
JSONArray ja = new JSONArray();
try {
HttpClient httpclient = new DefaultHttpClient();
Object sendDataUrl = null;
HttpPost request = new HttpPost(sendDataUrl.toString());
List<NameValuePair> params = new ArrayList<NameValuePair>();
ContextWrapper context = null;
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);
}
System.out.print(ja);
}
} catch (Exception e) {
// TODO: handle exception
}
finally {
// ... cleanup that will execute whether or not an error occurred ...
}
}catch (Exception e) {
// TODO: handle exception
}
finally {
// ... cleanup that will execute whether or not an error occurred ...
}
}}
抱歉,无法正确格式化代码.
Sorry cant get this to format the code properly.
推荐答案
此代码记录所有已安装应用程序的名称和包名称.您可以使用 LogCat 轻松检查日志(如果您使用的是 Eclipse).
This code logs name and package name of all the installed applications. You can easily check the log using LogCat (if you are using Eclipse).
包名称 - 应用包的名称.
名称 - 与应用程序关联的文本标签.您不能只使用 appInfo.name
,因为它会返回 null
.使用 appInfo.loadLabel(packageManager)
您会得到实际应用的名称,例如 Speech Recorder,而不是包名称 com.android.speechrecorder.
Name - text label associated with the application. You can't use just appInfo.name
as it will return null
. Using appInfo.loadLabel(packageManager)
you get the actual app's name like Speech Recorder instead of package name com.android.speechrecorder.
final PackageManager packageManager = getPackageManager();
List<ApplicationInfo> installedApplications =
packageManager.getInstalledApplications(PackageManager.GET_META_DATA);
for (ApplicationInfo appInfo : installedApplications)
{
Log.d("OUTPUT", "Package name : " + appInfo.packageName);
Log.d("OUTPUT", "Name: " + appInfo.loadLabel(packageManager));
}
这篇关于如何在安卓手机上安装所有应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在安卓手机上安装所有应用程序
基础教程推荐
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01