如何获得安装在Android手机的所有应用程序 [英] How to get all apps installed on android phone

查看:190
本文介绍了如何获得安装在Android手机的所有应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是在code,我拥有的一切,但我仍然不能让手机上的所有应用程序的列表。有谁看到我做错了什么?

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 ...
}
    }}

抱歉不能让这个正确格式化code。

Sorry cant get this to format the code properly.

推荐答案

这code日志名称和包的所有安装的应用程序名称。你可以很容易地检查使用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).

包名称 - 应用程序的软件包的名称

Package name - name of the app's package.

名称 - 与应用程序相关的文本标签。你不能只使用 appInfo.name ,因为它会返回。使用 appInfo.loadLabel(packageManager)你得到实际的应用程序的名称,比如语音记录器的,而不是包名的 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));
} 

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆