异常:java.lang.SecurityException

时间:2018-12-04 14:48:46

标签: android

这是例外情况->

Exception: java.lang.SecurityException
Ex. Message: Permission Denial: getTasks() from pid=16191, uid=10108 requires android.permission.GET_TASKS
Thread: Thread[main,5,main]
Memory Usage: 10 / 1454 MB (0%)

De-obfuscated stack trace:
===========================
java.lang.RuntimeException : Unable to start receiver com.tesco.clubcardmobile.notification.PushMessageReceiver: java.lang.SecurityException: Permission Denial: getTasks() from pid=16191, uid=10108 requires android.permission.GET_TASKS
at android.app.ActivityThread.handleReceiver(ActivityThread.java:2674)
at android.app.ActivityThread.access$1700(ActivityThread.java:166)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1359)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5590)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
at dalvik.system.NativeStart.main(NativeStart.java)
Caused by: java.lang.SecurityException : Permission Denial: getTasks() from pid=16191, uid=10108 requires android.permission.GET_TASKS
at android.os.Parcel.readException(Parcel.java:1472)
at android.os.Parcel.readException(Parcel.java:1426)
at android.app.ActivityManagerProxy.getTasks(ActivityManagerNative.java:2832)
at android.app.ActivityManager.getRunningTasks(ActivityManager.java:880)
at android.app.ActivityManager.getRunningTasks(ActivityManager.java:916)
at com.tesco.clubcardmobile.utils.CommonUtils.isAppRunningInBackground(android.content.Context)(SourceFile:337)
at com.tesco.clubcardmobile.notification.PushMessageReceiver.onReceive(android.content.Context,android.content.Intent)(SourceFile:67)
at android.app.ActivityThread.handleReceiver(ActivityThread.java:2667)
at android.app.ActivityThread.access$1700(ActivityThread.java:166)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1359)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5590)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
at dalvik.system.NativeStart.main(NativeStart.java)

我用来检查应用是在地面还是在后台

 public static boolean isAppRunningInBackground(Context context) {
        boolean isInBackground = true;
        ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
        if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT_WATCH) {
            List<ActivityManager.RunningAppProcessInfo> runningProcesses = am.getRunningAppProcesses();
            for (ActivityManager.RunningAppProcessInfo processInfo : runningProcesses) {
                if (processInfo.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND) {
                    for (String activeProcess : processInfo.pkgList) {
                        if (activeProcess.equals(context.getPackageName())) {
                            isInBackground = false;
                        }
                    }
                }
            }
        } else {
            List<ActivityManager.RunningTaskInfo> taskInfo = am.getRunningTasks(1);
            ComponentName componentInfo = taskInfo.get(0).topActivity;
            if (componentInfo.getPackageName().equals(context.getPackageName())) {
                isInBackground = false;
            }
        }

        return isInBackground;
    }

当我运行此代码时,我得到一些时间java.lang.SecurityException  我不认为需要为此目的启用任何权限,请启用我的所有权限,请告诉我我在做什么错了,此异常即将检查应用是否为地面或后台

0 个答案:

没有答案