0

I check by the process name. but I want to search by application name. How can I do that ? For example, facebook, whatsapp, instagram etc. to check if the applications are running? What string value should I send for this? isnamedprocessrunning ( "com.example.processlis");

will take the application name as string and will find it accordingly

MyService.java

public class MyService extends Service {

@Override
public void onCreate() {
    super.onCreate();
    isNamedProcessRunning("com.example.processlistener");


}

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    return super.onStartCommand(intent, flags, startId);
}

@Nullable
@Override
public IBinder onBind(Intent ıntent) {
    return null;
}

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

         }

MainActivity.java

  Intent startIntent = new Intent(this,MyService.class);
    startService(startIntent);
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Yavuz
  • 71
  • 1
  • 2
  • 7
  • Please refer this url (https://stackoverflow.com/questions/3278895/how-to-check-current-running-applications-in-android).Hope it helps – Muhammed Arshad K Feb 27 '18 at 10:56
  • that process is controlling as a name. I will check all the processes I want and check if it works according to the application name I wrote – Yavuz Feb 27 '18 at 11:01

0 Answers0