安卓:我怎样才能获得当前在屏幕上打开的应用程序名称 [英] Android: How can I get current opened application name on screen
本文介绍了安卓:我怎样才能获得当前在屏幕上打开的应用程序名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请建议我我怎样才能得到当前打开的应用程序名称,即使是在设备的主屏幕,然后我会找到主屏幕是开放的。
Please suggest me how can I get current open application name, even if there is home screen on device then I will find "Home screen is open".
推荐答案
在这里你去
ActivityManager am = (ActivityManager) this.getSystemService(ACTIVITY_SERVICE);
List l = am.getRecentTasks(1, ActivityManager.RECENT_WITH_EXCLUDED);
Iterator i = l.iterator();
PackageManager pm = this.getPackageManager();
while (i.hasNext()) {
ActivityManager.RunningAppProcessInfo info = (ActivityManager.RunningAppProcessInfo)(i.next());
try {
CharSequence c = pm.getApplicationLabel(pm.getApplicationInfo(
info.processName, PackageManager.GET_META_DATA));
Log.w("LABEL", c.toString());
} catch (Exception e) {
// Name Not FOund Exception
}
}
这篇关于安卓:我怎样才能获得当前在屏幕上打开的应用程序名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文