In manifest:
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
In Activity:
if (Build.VERSION.SDK_INT >= 33) {
if (ContextCompat.checkSelfPermission(this, Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.POST_NOTIFICATIONS},1);
}
else {
//
}
}
In the build.gradle file the targetSdkVersion is 34
I have other permission requests like Camera, Location, and Microphone, and all of these work fine, but the POST NOTIFICATIONS request doesn’t. The dialog box for asking the user to allow it doesn’t appear.
The notifications work only if I activate them manually in Settings -> App -> Notifications -> Allow Notifications
Don’t know what is the problem! Ohh and I know about this android developer resource
2
Answers
I made it work by grouping the Manifest.permission.POST_NOTIFICATIONS with the others:
The code above works!! But don't know why it didn't, in the previous stand-alone code. I even added toast and log lines to check if the IF condition was met, and all seemed OK except it didn't ask for the POST_NOTIFICATION permission.
I tried your code it is working fine for me:
Few things you can re-check:
Also more you can check in this answer