33

Trying to implement the notification permission for android 13 or "Tiramisu" but failed to get the import for that permission.

Currently: targeted SDK version is 32 compile SDK version is 32

I've declared it also in manifiest as below:

 <uses-permission android:name="android.permission.POST_NOTIFICATIONS"

import i'm using:

import android.Manifest
  • But even not getting import in my fragment.

enter image description here

a_local_nobody
  • 7,947
  • 5
  • 29
  • 51
Ammar
  • 765
  • 1
  • 8
  • 18
  • 1
    weird, [it is there](https://developer.android.com/reference/android/Manifest.permission#POST_NOTIFICATIONS). try to restart your Android Studio with cache cleaning (File ->Invalidate caches -> Invalidate and Restart button) – snachmsm May 26 '22 at 08:20
  • Does there any role for the Gradle version here? – Ammar May 26 '22 at 08:24

8 Answers8

28

Just add this import:

import android.Manifest
Joseph Wambura
  • 2,732
  • 2
  • 21
  • 24
23

I solved it by using compileSdkVersion 33 in the gradle file at the Module level. Then it allowed me to use the POST_NOTIFICATIONS permission without any issue. Gradle Settings

MatBuompy
  • 402
  • 5
  • 12
6
     android {
     namespace 'com.example.myapplication'
    compileSdkVersion 33//update this

     defaultConfig {
        applicationId "com.example.myapplication"
        minSdk 23
        targetSdkVersion 33//update this
        versionCode 1
        versionName "1.0"
        
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
Ammar
  • 765
  • 1
  • 8
  • 18
4

I faced the same problem,

Steps to fix :

Install SDK Platforms SDK Platform 33 Android TiramisuPrivacy Sandbox Preview

enter image description here

Install SDK Tools : Android SDK build Tools 33 enter image description here

Dev Soni
  • 489
  • 4
  • 12
3

You need to prefix the Manifest statement with android., e.g.,

            if (ContextCompat.checkSelfPermission(this, android.Manifest.permission.POST_NOTIFICATIONS) ==
                PackageManager.PERMISSION_GRANTED)
FractalBob
  • 3,225
  • 4
  • 29
  • 40
1

Set targetSDKVersion to 33.

If for some reason it complains about your minimum supported and you're in no position to update, use the following instead:

NotificationManagerCompat.from(this).areNotificationsEnabled()
Nestor Ledon
  • 1,925
  • 2
  • 23
  • 36
0

just import import android.Manifest.permission.POST_NOTIFICATIONS as POST_NOTIFICATIONS and use as ContextCompat.checkSelfPermission(context, POST_NOTIFICATIONS) it's work perfectly

  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community May 12 '23 at 15:26
0

if you are coming here for a react-native that uses 'react-native-gesture-handler' this is because react-native-gesture-handler has a new 2.10.0 version, if you downgrade it to 2.9.0 it should work

Davide Carpini
  • 1,581
  • 17
  • 15