1

I want to follow the running application. The code below is working when I write the process name. However I want to follow the application by typing in the name. How can I do that ? For example, facebook, twitter, instagram etc. and I will send toast the message according to the situation. How can I do that? I do not want to check with the process name.

MainActivity.java

public class MainActivity extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    isNamedProcessRunning("com.facebook.orca:videoplayer");
}



boolean isNamedProcessRunning(String processName){
    if (processName == null)
        return false;

    ActivityManager manager =
            (ActivityManager) this.getSystemService(ACTIVITY_SERVICE);
    List<ActivityManager.RunningAppProcessInfo> processes = manager.getRunningAppProcesses();
    for (ActivityManager.RunningAppProcessInfo process : processes)
    {
        if (processName.equals(process.processName))
        {
            Toast.makeText(this, "Same", Toast.LENGTH_SHORT).show();
            return true;
        }
    }
    Toast.makeText(this, "Different", Toast.LENGTH_SHORT).show();
    return false;
}
  }
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
matchs
  • 31
  • 6
  • I think for this you have to know the Running component class name at first place. – ADM Feb 23 '18 at 12:50
  • @LanceToth this question is different because i do to want app name – matchs Feb 23 '18 at 12:52
  • @ADM give me some more info – matchs Feb 23 '18 at 12:53
  • Check [ActivityManager.RunningAppProcessInfo](https://developer.android.com/reference/android/app/ActivityManager.RunningAppProcessInfo.html) .see if this workout for you . – ADM Feb 23 '18 at 13:05

0 Answers0