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));
}
这篇关于如何在安卓手机上安装所有应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在安卓手机上安装所有应用程序


- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- android 4中的android RadioButton问题 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- Android - 拆分 Drawable 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01