58

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) Commented May 26, 2022 at 8:20
  • Does there any role for the Gradle version here? Commented May 26, 2022 at 8:24

10 Answers 10

58

Just add this import:

import android.Manifest
Sign up to request clarification or add additional context in comments.

2 Comments

I wonder why Android Studio doesn't provide a quick action to add the import for us.
Android Studio also sees a Manifest class for your apps package, so doesn't see it as a missing import.
31

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 Comments

This did not work for me.
Did you install the Android API 33 SDK?
Oh yes, that is definately installed.
Well, I can't definately help if you don't provide additional info.
Btw, it does work now, it was a typo.
|
10

Add this to your java/kotlin file:

import android.Manifest

Manifest:
    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 Comments

Note: As of 26-05-2022 android 13 is not yet stable
Just thought it saved my day in advance. Thanks for this.
This did not work for me...
6

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

            if (ContextCompat.checkSelfPermission(this, android.Manifest.permission.POST_NOTIFICATIONS) ==
                PackageManager.PERMISSION_GRANTED)

Comments

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 Comment

Android TiramisuPrivacy Sandbox Preview is not needed. Try to File -> Invalidate Caches...
3

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()

Comments

3

Import below line

import android.Manifest

then use,

android.Manifest.permission.POST_NOTIFICATIONS

instead of

Manifest.permission.POST_NOTIFICATIONS

Comments

3

Import android Manifest

There is suggesting two manifest for importing. I solved the issue simply by import android manifest class(red one). Hope it helps someone.

two manifest file for import. select red one

Comments

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 Comment

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.
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

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.