40

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

2
  • 1
    weird, it is there. try to restart your Android Studio with cache cleaning (File ->Invalidate caches -> Invalidate and Restart button)
    – snachmsm
    May 26, 2022 at 8:20
  • Does there any role for the Gradle version here?
    – Ammar
    May 26, 2022 at 8:24

9 Answers 9

37

Just add this import:

import android.Manifest
2
  • 2
    I wonder why Android Studio doesn't provide a quick action to add the import for us. Mar 27 at 5:39
  • 1
    Android Studio also sees a Manifest class for your apps package, so doesn't see it as a missing import. Apr 15 at 23:36
27

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

7
  • 1
    This did not work for me.
    – Ted
    Dec 6, 2022 at 14:16
  • Did you install the Android API 33 SDK?
    – MatBuompy
    Dec 6, 2022 at 15:24
  • Oh yes, that is definately installed.
    – Ted
    Dec 7, 2022 at 5:30
  • Well, I can't definately help if you don't provide additional info.
    – MatBuompy
    Dec 7, 2022 at 8:00
  • Btw, it does work now, it was a typo.
    – Ted
    Dec 7, 2022 at 8:27
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"
    }
3
  • Note: As of 26-05-2022 android 13 is not yet stable
    – Ammar
    May 26, 2022 at 13:33
  • 1
    Just thought it saved my day in advance. Thanks for this. Aug 25, 2022 at 19:17
  • 1
    This did not work for me...
    – Ted
    Dec 6, 2022 at 14:21
5

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

1
  • Android TiramisuPrivacy Sandbox Preview is not needed. Try to File -> Invalidate Caches...
    – Eric Cen
    Jan 19 at 1:00
4

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

            if (ContextCompat.checkSelfPermission(this, android.Manifest.permission.POST_NOTIFICATIONS) ==
                PackageManager.PERMISSION_GRANTED)
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()
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
  • 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.
    – Community Bot
    May 12 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

-1

Import below line

import android.Manifest

then use,

android.Manifest.permission.POST_NOTIFICATIONS

instead of

Manifest.permission.POST_NOTIFICATIONS

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.