0

Whenever user open any app i need know if application is running on the UI thread. I also need to show a toast of the Package Name of that application.

I have user Activity Manager but it not working as it should. It always shows displayed Launcher.

 ActivityManager manager = (ActivityManager) this.getSystemService(Context.ACTIVITY_SERVICE);
 List<ActivityManager.RunningTaskInfo> runningTaskInfo = manager.getRunningTasks(1);
 ComponentName componentInfo = runningTaskInfo.get(0).topActivity;
 pack = componentInfo.getPackageName();

Can anyone tell me how I can use usage stats to achieve this?

Batuhan Coşkun
  • 2,961
  • 2
  • 31
  • 48

1 Answers1

0

As far as displaying the name of your package you can use PackageManager and getLaunchIntentForPackage()

  • can you please post some sample code i have using handler Handler handler = new Handler(Looper.getMainLooper()); handler.post(new Runnable() { @Override public void run() { if (isForeground().equals(packag)) { Toast.makeText(getApplicationContext(),"camera is open",Toast.LENGTH_SHORT).show(); } } }); – Ashokkumar Adichill Oct 23 '17 at 06:00