Fix: prevent allow notifications prompt on rotation#12201
Fix: prevent allow notifications prompt on rotation#12201VougJo23 wants to merge 1 commit intoTeamNewPipe:devfrom
Conversation
app/src/main/java/org/schabi/newpipe/util/PermissionHelper.java
Outdated
Show resolved
Hide resolved
app/src/main/java/org/schabi/newpipe/util/PermissionHelper.java
Outdated
Show resolved
Hide resolved
|
I posted some notes on the original issue: |
|
Okay here’s an answer by ChatGPT which I think corresponds exactly to what I figured out but in a pretty well-phrased manner: DetailsTo check whether a user has explicitly denied a permission in an Android app (especially if they selected "Don't ask again"), you can use a combination of the Key Concepts:
Code Example (Kotlin):val permission = Manifest.permission.CAMERA
when {
ContextCompat.checkSelfPermission(context, permission) == PackageManager.PERMISSION_GRANTED -> {
// Permission granted
}
ActivityCompat.shouldShowRequestPermissionRationale(activity, permission) -> {
// Permission denied before, but "Don't ask again" NOT selected
// Show rationale to user
}
else -> {
// Permission denied before AND "Don't ask again" selected
// Or first-time request on some devices
}
}Interpreting
|
This seems to be the only reliable way of making sure we only ever bother the user once. If they accept, from then on the permission check will be successful. If they deny or swipe away, we never ask again at startup and the user has to manually change it in the settings or go to our settings and re-do the prompt by activating notifications.
b7e5637 to
d63db94
Compare
|
@Stypox I think I fixed it and implemented it correctly with the |
|
| final SharedPreferences prefs2 = | ||
| PreferenceManager.getDefaultSharedPreferences(activity); | ||
| // commit setting before doing anything else | ||
| prefs2.edit().putBoolean(wasAskedKey, true).commit(); |
There was a problem hiding this comment.
Wait, this means that once it has been asked once, it will never ever be asked again. I just tested and if you dismiss the request by clicking outside of the permission dialog, NewPipe will never again ask. I think what we want is just to avoid asking twice in the same execution of the app. This can be achieved by setting wasAskedKey to false in App.onCreate(). Or probably directly using a boolean field in App is even better, without having to go through settings, since in theory the App instance is not recreated on orientation change.
|
@Profpatsch I have re-added "waiting for review" by renaming it to "ready for review" as earlier name was creating confusion sometimes with "waiting for author" label (atleast for me) & I had deleted it last time after couple of messups. Due to time constraints I couldn't get to it earlier. As I looked at it coming back after a break, It looked rude in github events history, Sorry for that friends, it was unintentional & now I have made the amends for good. |
|
@VougJo23 hello, are you still interested in working on this? In particular implementing the solution suggested in: #12201 (comment) . Let me know, otherwise this PR can be closed, thanks in advance! |
|
Closing for now since @Isaac-75 now wants to work on it. Thanks for the solutions explored so far! |



What is it?
Description of the changes in your PR
Add variable permissionStatus to check if the user has already granted or denied permission.
Before/After Screenshots/Screen Record
notificationfix-before.mp4
notificationfix-after.mp4
Fixes the following issue(s)
APK testing
The APK can be found by going to the "Checks" tab below the title. On the left pane, click on "CI", scroll down to "artifacts" and click "app" to download the zip file which contains the debug APK of this PR. You can find more info and a video demonstration on this wiki page.
Due diligence