简体   繁体   English

如何以编程方式获取当前在 android 最近堆栈中的应用程序的名称?

[英]How to programmatically get the names of apps that currently are in the recents stack of android?

I need some code to get an object or an arraylist that contains all the names of those applications that currently are in the recents stack of android .我需要一些代码来获取一个对象或一个数组列表,其中包含当前位于 android 的最近堆栈中的那些应用程序的所有名称。 Maybe android doesn't permit to do that (for security reasons) so even code which needs root permissions is ok for me.也许android不允许这样做(出于安全原因),所以即使是需要root权限的代码对我来说也可以。

Solution 1: 解决方案1:

Use getRunningAppProcesses , which will return a list of RunningAppProcessInfo objects that will give you some data about each running app. 使用getRunningAppProcesses ,它将返回RunningAppProcessInfo对象的列表,这些对象将为您提供有关每个正在运行的应用程序的一些数据。 One of the pieces of information you can retrieve about the app is its importance , which can have a value IMPORTANCE_FOREGROUND which indicates that the process is the currently active. 您可以检索到的有关该应用程序的信息之一就是它的importance ,它可以具有值IMPORTANCE_FOREGROUND ,指示该进程当前处于活动状态。

Some guide For you as well. 一些指南也为您。

IMPORTANCE_FOREGROUND

RunningAppProcessInfo

Solution 2: I was also developing an application for locking the apps. 解决方案2:我还在开发用于锁定应用程序的应用程序。 It seems you need to ask user to provide this setting. 似乎您需要要求用户提供此设置。 I used this activity to check which app is in foreground but I Guess it can work according to you also. 我使用此活动来检查哪个应用程序处于前台,但我想它也可以根据您的要求工作。

Settings.ACTION_USAGE_ACCESS_SETTINGS

On my mobile It's written 在我的手机上写道

Allow apps to monitor which other apps you use and how often,and identify your service provider, language and other usage data. 允许应用监控您使用其他哪些应用以及使用频率,并识别您的服务提供商,语言和其他使用数据。

UsageStatsManager has some useful methods that can satisfy your need. UsageStatsManager有一些有用的方法可以满足您的需求。

i think you need to ask this from your user and if the user agrees. 我认为您需要向您的用户询问,以及用户是否同意。 you can use gain access to the recent Apps. 您可以使用访问最新应用程序的权限。

I had a look around and your question could be answered here: 我环顾四周,您的问题可以在这里回答:
How to get App info from RecentTaskInfo? 如何从最近任务信息中获取应用信息? It's based on ActivityManager.RecentTaskInfo 它基于ActivityManager.RecentTaskInfo

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

相关问题 如何获取Android中后台运行的应用程序的名称? - How to get names of background running apps in android? 如何以编程方式在 android 中获取当前选择的应用程序 package 名称? - how to get currently selected application package name in android programmatically? 以编程方式更改Android中主屏幕应用程序的图标/名称 - Programmatically change the icons/names of homescreen apps in Android Android:获取当前打开的应用程序的堆栈(数组) - Android: Get the stack (array) of currently opened applications 有没有办法在Android中获取所有当前处于活动状态的应用程序? - Is there a way to get all currently active apps in Android? 如何在Android中以编程方式查找当前正在运行的应用程序? - How to find the currently running applications programmatically in Android? 如何以编程方式确定Android中当前处于活动状态的App - How to programmatically determine the currently active App in Android 如何获取在Android中以编程方式使用位置的应用列表? - How to get list of apps that use location programmatically in Android? 如何在Android中获取堆栈跟踪C ++函数名称 - how to get stack trace c++ functions names in android 如何获取Android中默认应用程序包的规范名称 - how do i get canonical names of packages of deafult apps in Android
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM