本文介绍了跟踪第三方应用程序的启动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以跟踪设备上第三方应用程序的启动?
Is it possible to track the launch of a third-party application on the device? Maybe the android sends a broadcast when the applications are launched.
更新
public class ServiceAppControl extends IntentService {
private boolean serviceStarted = true;
public ServiceAppControl() {
super("ServiceAppControl");
}
@Override
protected void onHandleIntent(@Nullable Intent intent) {
while (serviceStarted){
String appIsForeground = isAppOnForeground(getBaseContext());
Log.d(AppGlobal.LOG_TAG, "Запущено приложение " + appIsForeground);
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
private String isAppOnForeground(Context context) {
ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningAppProcessInfo> appProcesses = activityManager.getRunningAppProcesses();
String appIsForeground = "";
if (appProcesses == null) {
return appIsForeground;
}
final String packageName = context.getPackageName();
for (ActivityManager.RunningAppProcessInfo appProcess : appProcesses) {
if (appProcess.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND) {
appIsForeground = appProcess.processName;
return appIsForeground;
}
}
return appIsForeground;
}
}
推荐答案
没有广播这样的消息来通知其他人可以收听的应用程序的启动,因为这可能是安全威胁。人们可以将其用于恶意目的。否则,您可以从日志中了解当前启动的应用程序。
There is no broadcast as such to inform about launch of an application to which others can listen because that can be a security threat. People can use it for malicious purpose. Otherwise from the logs you can get to know about currently launched application.
这篇关于跟踪第三方应用程序的启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!