Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
942 views
in Technique[技术] by (71.8m points)

permissions - Why android API:getNotificationPolicy can't run successfully on some emulator with specific sdk version?

The Unit Test code is attached:

    import android.app.NotificationManager;
    import android.app.NotificationManager.Policy;
    import android.content.Context;
    import androidx.test.InstrumentationRegistry;
    import androidx.test.runner.AndroidJUnit4;
    import org.junit.Test;
    import org.junit.runner.RunWith;

    @RunWith(AndroidJUnit4.class)
    public class TestCase_com_cabooze_buzzoff__1592700345 {
      @Test
      public void testCase() throws Exception {
         Context var1 = InstrumentationRegistry.getTargetContext();
         Object var2 = var1.getSystemService("notification");
         NotificationManager var3 = (NotificationManager)var2;
         Policy var4 = var3.getNotificationPolicy();
      }
    }

I run the above code on sdk 21-29 and the results are :

21-22:NoSuchMethodError

23-27:SecurityException

28-29:success

The minSDKVersion of my apk is 21; targetSDKVersion is 30.

I am wondering why getNotificationPolicy will throw SecurityException on 23-27, considering the google doc yield that getNotificationPolicy need android.permission.ACCESS_NOTIFICATION_POLICY which is a normal permission. Besides, why it can run successfully on 28-29.

question from:https://stackoverflow.com/questions/65648936/why-android-apigetnotificationpolicy-cant-run-successfully-on-some-emulator-wi

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...