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