android获取用户当前正在打开的应用程序的信息
2012-08-27 09:01
627 查看
需要用到ActivityManager.
getRunningTasks(int maxNum)
public List<ActivityManager.RunningTaskInfo>
getRunningTasks(int maxNum)
API介绍说:
Return a list of the tasks that are currently running, with the most recent being first and older ones after in order. Note that "running" does not mean any of the task's code is currently loaded or activity -- the task may
have been frozen by the system, so that it can be restarted in its previous state when next brought to the foreground.
当我们把1传递给maxNum时,返回的就是当前运行的那个TASK,然后就可以从task中获取最顶层的activity,此activity就是当前显示给用户那个activity。
getRunningTasks(int maxNum)
public List<ActivityManager.RunningTaskInfo>
getRunningTasks(int maxNum)
API介绍说:
Return a list of the tasks that are currently running, with the most recent being first and older ones after in order. Note that "running" does not mean any of the task's code is currently loaded or activity -- the task may
have been frozen by the system, so that it can be restarted in its previous state when next brought to the foreground.
maxNum | The maximum number of entries to return in the list. The actual number returned may be smaller, depending on how many tasks the user has started. |
---|
1 | ActivityManager am = (ActivityManager) getSystemService(ACTIVITY_SERVICE); |
2 | ComponentName cn = am.getRunningTasks( 1 ).get( 0 ).topActivity; |
3 | Log.d( "" , "pkg:" +cn.getPackageName()); |
4 | Log.d( "" , "cls:" +cn.getClassName()); |
相关文章推荐
- Android如何判断当前手机是否正在播放音乐,并获取到正在播放的音乐的信息
- Android如何判断当前手机是否正在播放音乐,并获取到正在播放的音乐的信息
- Android如何判断当前手机是否正在播放音乐,并获取到正在播放的音乐的信息
- Android如何判断当前手机是否正在播放音乐,并获取到正在播放的音乐的信息
- Android如何判断当前手机是否正在播放音乐,并获取到正在播放的音乐的信息
- Android如何判断当前手机是否正在播放音乐,并获取到正在播放的音乐的信息
- Android如何判断当前手机是否正在播放音乐,并获取到正在播放的音乐的信息
- Android中获取当前正在运行服务信息
- Android如何判断当前手机是否正在播放音乐,并获取到正在播放的音乐的信息
- Android获取当前系统正在运行应用及其数据流量
- android 获取当前系统及应用信息(二)
- 在SharePoint中无代码开发InfoPath应用: 获取当前用户信息
- android使用百度地图定位(获取当前经纬度和地址信息)
- spring security 获取当前用户信息
- Access无法启动应用程序,工作组信息文件丢失,或是已被其他用户已独占方式打开
- Android获取当前正在运行的线程和使用的内存
- Android获取应用程序信息——PackageManager的基本使用
- Android中如何获取系统应用程序列表与AndroidManifest.xml信息
- Android中获取正在运行的应用程序-----ActivityManager.RunningAppProcessInfo类详解
- Spring security 获取当前用户的登录信息