Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to know if user has disabled Picture in Picture feature permission?

enter image description here

and here is another example:

enter image description here

from the screenshot above we see user is able to disable picture in picture mode. you can find it in the "special app access" screen on the emulator api 27 . How can i detect if user has disabled this feature ?

i tried checking the following but it does not work:

packageManager.hasSystemFeature(PackageManager.FEATURE_PICTURE_IN_PICTURE)

compiler states that AppOpsManager cannot be found. any ideas ?

like image 354
j2emanue Avatar asked Oct 01 '18 15:10

j2emanue


People also ask

What is Picture-in-picture permission?

PiP is a special type of multi-window mode mostly used for video playback. It lets the user watch a video in a small window pinned to a corner of the screen while navigating between apps or browsing content on the main screen.


2 Answers

just like AlexTa said. but i wanted to actually write the code to save someone some time:

private fun hasPermission(): Boolean {
    val appOps = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        getSystemService(Context.APP_OPS_SERVICE) as AppOpsManager
    } else {
        return false
    }
    return appOps.checkOpNoThrow(AppOpsManager.OPSTR_PICTURE_IN_PICTURE, android.os.Process.myUid(), packageName) == AppOpsManager.MODE_ALLOWED
}
like image 104
j2emanue Avatar answered Sep 19 '22 17:09

j2emanue


Try AppOpsManager.checkOp (String op, int uid, String packageName), where op is OPSTR_PICTURE_IN_PICTURE operation. That method should return MODE_ALLOWED constant if supports Picture in Picture operation.

For more info, check this link.

like image 38
AlexTa Avatar answered Sep 22 '22 17:09

AlexTa