如何监视应用程序在前台swaping? [英] How to monitoring app swaping in foreground?

查看:146
本文介绍了如何监视应用程序在前台swaping?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当在后台我的应用程序运行。它需要监听其他应用程序swaping在前台,并得到他们的名字。如何实现?
   即当一个应用程序转到这个前景。我的应用程序必须通知。那么它的名字。

when my application run in background. It need to monitoring others application swaping in the foreground and get their name. How to implement? i.e. When an app goto the foreground. My app must be notified. then gets its name.

推荐答案

有关监督你可以使用的 ActivityManager 获取目前的顶级机应用的活动栈在你机应用:

For monitoring other Applications you can use ActivityManager for getting current top Appliction for Activity Stack as in Your Appliction:

ActivityManager am = (ActivityManager)context.getSystemService(Context. ACTIVITY_SERVICE);
List<ActivityManager.RunningTaskInfo> processes1 = activityManager.getRunningTasks(1);
ComponentName componentInfo = processes1.get(0).topActivity;
String classname =processes1.get(0).topActivity.getClassName(); 
String packagename = processes1.get(0).topActivity.getPackageName();

这篇关于如何监视应用程序在前台swaping?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆