android如何过滤出在launch界面显示的应用
时间: 2024-03-12 07:49:43 浏览: 33
在 Android 中,只有在启动器(Launcher)中显示的应用程序才会出现在设备的应用列表中。因此,可以通过查询所有的应用程序信息,然后过滤出具有启动器 Intent 的应用程序,即可得到在启动器中显示的应用程序。
具体的代码如下:
```java
// 创建一个查询启动器的 Intent
Intent launcherIntent = new Intent(Intent.ACTION_MAIN);
launcherIntent.addCategory(Intent.CATEGORY_LAUNCHER);
// 查询所有的应用程序信息
List<ResolveInfo> resolveInfoList = getPackageManager().queryIntentActivities(launcherIntent, 0);
// 过滤出具有启动器 Intent 的应用程序
List<String> packageNameList = new ArrayList<>();
for (ResolveInfo resolveInfo : resolveInfoList) {
packageNameList.add(resolveInfo.activityInfo.packageName);
}
```
其中,`Intent.ACTION_MAIN`和`Intent.CATEGORY_LAUNCHER`是查询启动器的 Intent。`getPackageManager().queryIntentActivities(launcherIntent, 0)`方法可以获取可以处理启动器的所有应用程序信息列表。遍历列表,将具有启动器 Intent 的应用程序的包名添加到列表中。最终得到的`packageNameList`就是在启动器中显示的应用程序的包名列表。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)