如何在安卓手机上安装所有应用程序

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));
} 

这篇关于如何在安卓手机上安装所有应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:如何在安卓手机上安装所有应用程序

基础教程推荐