跟踪第三方应用程序的启动

时间:2017-06-07 09:01:07

标签: android broadcastreceiver

是否可以在设备上跟踪第三方应用程序的启动?也许android会在启动应用程序时发送广播。

更新

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

}

3 个答案:

答案 0 :(得分:0)

是的,这在Android中是可行的。您可以使用以下代码

检查第三方应用程序是否在forground中或在后台
Sub ab_notsonull()
Dim X As String, cell As Range
For Each cell In Range("A1:A3")
  If (Len(cell.Value) > 0) Then
  X = X & ("-" & cell.Value & Chr(10))
End If
Next
Range("B2").Value = Left$(X, Len(X) - 1)
Range("B2").WrapText = True
Range("B2").Columns.AutoFit
End Sub

答案 1 :(得分:0)

没有广播可以告知其他人可以收听的应用程序的启动,因为这可能是一种安全威胁。人们可以将其用于恶意目的。否则,您可以从日志中了解当前启动的应用程序。

答案 2 :(得分:0)

首先,回答您的问题,是否可以在设备上跟踪第三方应用程序的启动? -

检查this链接,我简要解释过。

注意: 在做一些事情之前我们应该知道一些事情

  • 持续运行while循环或计时器并获取最近的应用程序 将耗尽大量电池(所有AppLocker将采取相同的方式来获得当前的开放应用程序),但我们 应该足够聪明,我们应该只在运行循环时 屏幕亮起,当屏幕关闭时我们应该停止该计时器或其他什么。

  • 来自Android&#34; O&#34;运行服务的一些限制 背景,所以最好将您的服务设为Foreground service

完成!!!

相关问题