简体   繁体   English

如何获取所有已安装应用的列表?

[英]How can I get a list of all installed apps?

Help! 救命! All the same the black screen. 黑屏一样。 Show as it is necessary to add a code. 显示,因为有必要添加代码。 Thanks. 谢谢。 I use such code: 我用这样的代码:

package com.tipfile;

import java.util.ArrayList;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;


public class dop extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.dop);
    PackageManager pm = this.getPackageManager();

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

    ArrayList<ResolveInfo> list = (ArrayList<ResolveInfo>) 
    pm.queryIntentActivities(intent, PackageManager.PERMISSION_GRANTED);
    for (ResolveInfo rInfo : list) {
    System.out.println("Installed Applications " + rInfo.activityInfo.applicationInfo.loadLabel(pm).toString());
    }
    ListView listView = (ListView) findViewById(R.id.list);
    ArrayAdapter<String> aa = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1);
    listView.setAdapter(aa);
}}
  ArrayAdapter<String> aa = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1);
    listView.setAdapter(aa);

You dont initialize aa with any data hence the black screen. 你不用任何数据初始化aa因此黑屏。

You can build a List<String> variable from ArrayList<ResolveInfo> list = (ArrayList<ResolveInfo>) and use the ArrayAdapter constructor that accepts a list to fill aa 您可以从ArrayList<ResolveInfo> list = (ArrayList<ResolveInfo>)构建List<String>变量,并使用接受列表填充aaArrayAdapter构造函数

EDIT 编辑

List<String> myList = new ArrayList<String>();
ArrayList<ResolveInfo> list = (ArrayList<ResolveInfo>) pm.queryIntentActivities(intent, PackageManager.PERMISSION_GRANTED);
for (ResolveInfo rInfo : list) {
    System.out.println("Installed Applications " + rInfo.activityInfo.applicationInfo.loadLabel(pm).toString());
myList.add(rInfo.activityInfo.applicationInfo.loadLabel(pm).toString());
}

ListView listView = (ListView) findViewById(R.id.list);
ArrayAdapter<String> aa = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, myList);
listView.setAdapter(aa);
ArrayAdapter<String> aa = new
ArrayAdapter<String>(this,android.R.layout.simple_list_item_1);

Change these lines into 将这些行改为

ArrayAdapter<String> aa = new
ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,list);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 android 中,如何获取所有已安装的外部 memory 的列表 - In android how can I get a list of all external memory installed 如何在列表中获取所有共享应用程序(安装在设备上)? - How to get all share apps (installed on the device) in a list? 为什么在 Flutter 中无法获取 Android 的已安装应用程序列表? - Why can't I get a list of installed apps for Android in Flutter? Android获取所有已安装应用的列表 - Android get a list of all installed apps 使用cordova如何获得Android设备上已安装的应用程序列表? - Using cordova how can i get list of installed apps on android device? 如何阅读iOS上安装的所有应用程序的列表 - How to read list of all apps installed on iOS 如何获取所有应用列表,包括系统应用和用户安装的应用? - How to get all the app list including System APPS and user installed APPS? 如何在Android手机上安装所有应用程序 - How to get all apps installed on android phone 如何获取 Android 设备上已安装应用程序的列表 - How to get a list of installed apps on Android device 如何获取已安装的即时通讯应用程序列表? - how to get list of installed instant messenger apps?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM