如何检索所有已安装的Andr​​oid应用Andr、oid

2023-09-07 01:52:17 作者:紧紧闭上双眼

之前就已经做了我的#1和谷歌搜索,但我无法找到工作了,我为我在使用它们时会出错的任何答案或有一定的codeS /配件缺失,或者有可能是一个需要安装额外的库文件。

Did my search on the Stackoverflow and Google before already but I could not find any answer that worked out for me as I get errors when using them or that there are certain codes/parts missing or, that there could be a need to install additional library files.

所以基本上我想要做的是检索所有安装的应用程序在Android手机上,并显示出来,但我不知道是如何去这样做。我经常碰到关于背景变量或我的XML文件不匹配,或另一种方式.java文件错误。

So basically what I want to do is to retrieve all the installed apps in the android phone and display it out but I have no clue as to how to go about doing it. I usually run into error regarding the "context" variable or that my xml files does not match the .java files in one way or another.

会有人好心地给我源$ C ​​$ CS所有以达到获取所有的Andr​​oid应用程序的目标所需要的文件(如XML,JAVA,清单,绘制,布局等)?帮助将非常AP preciated

Would anyone be kind enough to give me the source codes for all the required files(e.g. xml, java, manifest, drawable, layout etc) in order to achieve the objective of retrieving all android apps? Help would be very much appreciated

推荐答案

首先创建的main.xml文件,如下所示,

First create main.xml file as follows,

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

            <ListView
                android:id="@+id/list1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" >
            </ListView>

</LinearLayout>

列表将被用于填充安装的应用程序,

This list will be used to populate the installed applications,

现在创建活动类,以获取安装的应用程序,

Now create the Activity class to fetch the installed applications,

public class AppList extends Activity {
    private ListView lView;
    private ArrayList results;
    List<ResolveInfo> list;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
            results = new ArrayList();
        lView = (ListView) findViewById(R.id.list1);
        PackageManager pm = this.getPackageManager();

        Intent intent = new Intent(Intent.ACTION_MAIN, null);
        intent.addCategory(Intent.CATEGORY_LAUNCHER);

        list = pm.queryIntentActivities(intent,
            PackageManager.PERMISSION_GRANTED);
        for (ResolveInfo rInfo : list) {
            results.add(rInfo.activityInfo.applicationInfo.loadLabel(pm)
                    .toString());
            Log.w("Installed Applications", rInfo.activityInfo.applicationInfo
                    .loadLabel(pm).toString());
        }
        lView.setAdapter(new ArrayAdapter(this,
                android.R.layout.simple_list_item_1, results));
    }
}

修改 - 如果您想从列表中打开应用程序,一旦你点击它。你必须覆盖的ListView的onItemClick方法和在该方法中,你必须通过意向打开选定的应用程序。

Edit- If you want to open the application from the list, once you click it. You have to override the onItemClick method of the ListView and in that method, you have to pass the intent to open the selected application.

在这里看一看,

从另一个应用程序启动一个应用程序 如何获得安装Android应用程序的列表,并选择一个运行 Launch an Application from Another Application How to get a list of installed android applications and pick one to run

这些将最有可能解决您的问题。

These will most probably solve your issue.