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;
}
}