简体   繁体   English

Android Studio如何将已安装的应用程序列表打印到listView中

[英]android studio how to print list of installed apps into a listView

I've found some code on the internet to obtain details of currently installed apps, I'm not sure how to implement this into a list. 我在互联网上找到了一些代码来获取当前安装的应用程序的详细信息,但不确定如何将其实现到列表中。 I've created the list in the xml file but I'm not too sure how to implement the data into the listView. 我已经在xml文件中创建了列表,但是我不太确定如何将数据实现到listView中。 The code to obtain the app data is - 获取应用数据的代码是-

     final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
  mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
  final List pkgAppsList = getPackageManager().queryIntentActivities(      mainIntent, 0);
  for (Object object : pkgAppsList) 
  {
ResolveInfo info = (ResolveInfo) object;
Drawable icon    = getBaseContext().getPackageManager().getApplicationIcon(info.activityInfo.applicationInfo);
String strAppName   = info.activityInfo.applicationInfo.publicSourceDir.toString();
String strPackageName  = info.activityInfo.applicationInfo.packageName.toString();
final String title  = (String)((info != null) ? getBaseContext().getPackageManager().getApplicationLabel(info.activityInfo.applicationInfo) : "???");

} }

You can first create a list of String like this: 您可以首先创建一个String列表,如下所示:

    final ArrayList<String> list = new ArrayList<String>();

then inside your code, add strAppName into the list by list.add(strAppName); 然后在您的代码中,通过list.add(strAppName);将strAppName添加到列表中list.add(strAppName);

and make an array adapter and set it to your listview: 并制作一个阵列适配器并将其设置为您的列表视图:

    final ListView listview = (ListView) findViewById(R.id.listview);
    final ArrayAdapter adapter = new ArrayAdapter(this,
            android.R.layout.simple_list_item_1, list);
    listview.setAdapter(adapter);

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

相关问题 如何获取 Android 11 中已安装应用程序的列表 - How to get a list of installed apps in Android 11 Android Studio安装的重复应用 - Duplicated apps installed by Android Studio 列出已安装的Android应用 - List out the installed apps android 如何在 android studio 中仅加载安装在设备中的 upi 应用程序 - How to load only upi apps installed in device in android studio 在Android的列表视图行中打印应用程序的安装状态 - Print app installed status in a listview line Android 如何列出仅在Android中的SD卡上安装或运行的应用程序数量? - How to list number of apps installed or running only on the sd card in Android? Android:如何获取使用Internet访问的已安装应用程序列表-PackageManager - Android : How to get the List of Installed apps that use Internet Access - PackageManager Android:如何从已安装的用户应用程序中创建复选框列表 - Android: how to do a checkbox list from installed user apps 如何获取用户在 Android 设备上安装的应用列表? - How to get the list of apps that have been installed by a user on an Android device? 如何在 Android 中不使用 ListView/RecyclerView/CardView 等显示已安装的应用程序? - How to display installed apps without using ListView/RecyclerView/CardView etc in Android?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM