请建议我如何获得当前打开的应用程序名称,即使设备上有主屏幕,我也会发现“主屏幕已打开”. 干得好 ActivityManager am = (ActivityManager) this.getSystemService(ACTIVITY_SERVICE);List l = am.getRecentTas
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 } }