1

This is exception coming ->

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)

this method i have use to check app is in for-ground or in background

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

when i run this code i am getting some time java.lang.SecurityException i dont think is any permission required for this i have enabled every permission please suggest me what i am doing wrong this exception is coming to check App is for-ground or in background

Bhaskar Mart
  • 47
  • 10
  • You can't use that method as of Android Lollipop. – TheWanderer Dec 04 '18 at 14:49
  • @TheWanderer can you tell me which method we have to check what wrong i am doing please suggest app is crashing – Bhaskar Mart Dec 04 '18 at 14:50
  • Possible duplicate of [Determining the current foreground application from a background task or service](https://stackoverflow.com/questions/2166961/determining-the-current-foreground-application-from-a-background-task-or-service) – TheWanderer Dec 04 '18 at 14:53
  • thanx @TheWanderer using permission issue fixed but android.permission.GET_TASKS is depricated – Bhaskar Mart Dec 05 '18 at 06:19

0 Answers0