[英]how can I know that certain app. in android is launched through my Application
I want do design App. 我要设计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: 您好,您可以使用PackageManager类别:
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 ). 我想您需要查看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 我没有对此进行测试,但是此链接也可能会有所帮助: 在Android中自动关闭应用程序
您只能看到已启动的应用程序列表,并且不能通过自己的应用程序杀死其他应用程序,因为它是由OS处理的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.