简体   繁体   中英

how can I know that certain app. in android is launched through my Application

I want do design App. which will able to detect that the a particular app. is launched and I want to kill it( if it is in a block list). How can I implement this?

Hello you can use the PackageManager clas for this:

    List<PackageInfo> pInfos = getPackageManager().getInstalledPackages(PackageManager.GET_ACTIVITIES);
for (PackageInfo pInfo : pInfos) {
  ActivityInfo[] aInfos = pInfo.activities;
  if (aInfos != null) {
    for (ActivityInfo activityInfo : aInfos) {
      Log.i("ACT", activityInfo.name);
      // do whatever else you like... 
    }
  }
}

I guess you need to look at the ActivityManager ( http://developer.android.com/reference/android/app/ActivityManager.html ). This will help you to find the running process. Perhaps this helps:

boolean ProcessRunning(String name) {
        ActivityManager manager = (ActivityManager) this.getSystemService(ACTIVITY_SERVICE);
        List<RunningProcess> processes = manager.getRunningAppProcesses();
        for (RunningProcess process : processes) {
            if (name.equals(process.name)) {
                return true;
            }
        }
        return false;
}

I didn't test this, but this link could also be helpful: Automate closing of applications in Android

您只能看到已启动的应用程序列表,并且不能通过自己的应用程序杀死其他应用程序,因为它是由OS处理的。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM