IT Share you

Android M 권한 대화 상자가 표시되지 않음

shareyou 2020. 11. 9. 21:36
반응형

Android M 권한 대화 상자가 표시되지 않음


현재 내 애플리케이션을 Android M의 새로운 권한 모델에 맞게 조정하려고합니다.

필요한 모든 권한을 수집 한 다음 실행합니다.

Log.i("Permissions", "Requesting permissions: " + permissions);
requestPermissions(requiredPermissions.toArray(new String[requiredPermissions.size()]), requestCodeForPermissions);

requiredPermissions에는 필요한 권한이 android.permission.WRITE_EXTERNAL_STORAGE있습니다.

해당 루틴은 logcat에 Log 줄이 있으므로 확실히 실행됩니다.

08-07 12:52:46.469: I/Permissions(1674): Requesting permissions: android.permission.RECEIVE_BOOT_COMPLETED; android.permission.WRITE_EXTERNAL_STORAGE

그러나 권한 대화 상자는 표시되지 않으며 onRequestPermissionsResult ()가 호출됩니다.

내가 도대체 ​​뭘 잘못하고있는 겁니까? 일부 자습서를 기반으로 나는 아무것도 놓친 것이 없다는 것을 알았습니다. 테스트 용 에뮬레이터 만 있고 물리적 장치는 없습니다. 설정의 정보 화면입니다 : 이미지

다른 것을 언급 할 가치가 있습니다. 홈 화면에서 설치된 앱의 개요를 열려고하면 launcher3 has exited. 관련이 있는지 잘 모르겠습니다.

아무도 왜 표시되지 않는지 알고 있습니까?


같은 문제가 발생했지만 나중에 매니페스트 파일에 권한을 추가하는 것을 잊었습니다. uses-permission 태그를 추가 한 후 시스템이 대화 상자를 표시했습니다. 누군가를 도울 수도 있습니다.


문제의 원인을 찾는 데 하루 종일 걸렸습니다. 원래의 대답은 나를 도왔다.

다음 tools:remove="android:maxSdkVersion"과 같이 추가하여 수정했습니다 .

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" tools:remove="android:maxSdkVersion"/>

REQUEST_CODE로 음수 값을 사용했기 때문에 동일한 문제가 발생했습니다.

requestPermissions(new String[]{android.Manifest.permission.CAMERA}, -1)

양수 값을 사용한 후 시스템이 대화 상자를 표시했습니다. 누군가에게 도움이되기를 바랍니다.


Hilal의 의견을 기반으로합니다 (고마워요!) : 제 경우에는 내 앱이 실제로 탭 호스트를 사용하고 있으며 권한은 탭 호스트 내부의 활동에서 요청되었습니다. 권한을 요청하는 별도의 활동을 시작한 후 작동합니다.


나는 단지 같은 문제가 있었다. 내 문제는 매니페스트의 잘못된 위치에 권한을 작성했다는 것입니다. 사용 권한이 애플리케이션 외부에 있는지 확인하십시오.

    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.google.android.gms.samples.vision.face.photo"
    android:installLocation="auto"
    android:versionCode="1"
    android:versionName="1" >

    <uses-sdk
        android:minSdkVersion="9"
        android:targetSdkVersion="21" />

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>


    <application
        android:hardwareAccelerated="true"
        android:label="FacePhotoDemo"
        android:allowBackup="true"
        android:icon="@drawable/icon">

더하다

 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

AndroidManifest.xml에서

참고 : 얻고 자하는 권한. 예 : android.permission.ACCESS_FINE_LOCATION 등


또한 권한 대화 상자가 나타나지 않거나 <uses-permission-sdk23>요소를 사용할 때 응용 프로그램이 충돌하는 상황이 발생 했지만 그 원인은 현재 6.0 장치의 시스템 버그 인 것으로 보입니다.

https://code.google.com/p/android/issues/detail?id=189841

충돌 예외 :

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.packageinstaller/com.android.packageinstaller.permission.ui.GrantPermissionsActivity}: java.lang.NullPointerException: Attempt to get length of null array

동일한 문제가 있으며 다음과 같이 shouldShowRequestPermissionRationale을 추가하면 문제가 해결됩니다.

if (ActivityCompat.shouldShowRequestPermissionRationale(thisActivity,
        Manifest.permission.READ_CONTACTS)) {

} else {
    ActivityCompat.requestPermissions(thisActivity,
            new String[]{Manifest.permission.READ_CONTACTS},
            MY_PERMISSIONS_REQUEST_READ_CONTACTS);

}

@shanraisshan의 답변에 추가하려면 REQUEST_CODE실제로 음수가 아닌 0보다 커야합니다.


우리 코드에서는 단순한 철자 오류였습니다.

우리는 :

<uses-permission android:name="android.permission.ACCESS_COURSE_LOCATION" /> 

그것은해야한다:

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

나는 위의 답변에서 말한 모든 것을했지만 여전히 대화가 표시되지 않고 gradle로 변경 targetSdkVersion되어 23나타났습니다. 이것이 누군가를 돕기를 바랍니다.


권한은 범주로 구성되므로 중요하지 않은 권한은 대화 상자가 표시되지 않고 부여됩니다.

이 문제가있는 경우 read_contacts와 같은 중요한 권한으로 변경하면 흐름을 테스트하고 문제가 권한이 중요하지 않은지 아니면 다른 권한인지 확인할 수 있습니다.

일반 보호 권한이 여기 에 나열 됩니다.


매니페스트에서 나는 변경

 <uses-permission
    android:name="android.permission.WRITE_EXTERNAL_STORAGE"
    android:maxSdkVersion="22" />

...에

 <uses-permission
    android:name="android.permission.WRITE_EXTERNAL_STORAGE"
     />

아마도 도움이 될 것입니다.


If anyone of you guys has an application that changes/modifies WRITE_SETTINGS and are facing this issue. Check out CommonsWare's Answer to WRITE_SETTINGS Ambiguity

I was facing this issue for 2 weeks and later realised that this issue was due to the fact that requestPermissions doesn't work for requesting WRITE_SETTINGS permission. Hope this helps :D


In my case I had requested "ACCESS_COARSE_LOCATION" in my manifest file and then request for "ACCESS_FINE_LOCATION" permission in code that's why the Permission Dialog was not opening.


In my case, the permission I was requesting (WRITE_SETTINGS) was more special and required Settings Activity to launch. So dialog was not showing up.

I had to get its permission using the following code:

Intent intent = new Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS);
intent.setData(Uri.parse("package:" + context.getPackageName()));
startActivityForResult(intent, CODE_WRITE_SETTINGS_PERMISSION);

Yet another cause for not getting the permission dialog to show when requesting a dangerous permission...

I had to do Build -> Clean Project and then Build -> Rebuild Project. I guess Android Studio didn't pick up on the changes I made in the manifest.


I had a similar issue caused by the wrong case of the permission constant in the manifest, I was using read_contacts in lower case:

<uses-permission android:name="android.permission.read_contacts" />

After changing read_contacts to uppercase it started working as expected

<uses-permission android:name="android.permission.READ_CONTACTS" />

After searching a while it appears it is required to set the value compileSdkVersion to "android-MNC" or as of today to 23. That requires the Gradle build system which then seems to require Android Studio. At least I couldn't find a single manual about how to set it outside the gradle files.


@Override
    public final void validateRequestPermissionsRequestCode(int requestCode) {
       // We use 16 bits of the request code to encode the fragment id when
       // requesting permissions from a fragment. Hence, requestPermissions()
       // should validate the code against that but we cannot override it as we
       // can not then call super and also the ActivityCompat would call back to
       // this override. To handle this we use dependency inversion where we are
       // the validator of request codes when requesting permissions in
       // ActivityCompat.
        if (!mRequestedPermissionsFromFragment
                && requestCode != -1 && (requestCode & 0xffff0000) != 0) {
            throw new IllegalArgumentException("Can only use lower 16 bits for requestCode");
        }
    }

Had the same issue. Later I realized that we have to declare each and every permission in manifest (even if one is a subclass of another). In my case I declared

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

in my manifest and was trying to access user's coarse location.

ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION)

Fixed the problem by adding coarse permission as well in manifest.

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>

Add permission in the manifest file as well.


Set your targetSdkVersion to 22.


had the same (i guess) problem and the solution was removing

import <app package>.Manifest;

autoimported by Android Studio at the top of the file and substitute it with

import android.Manifest; 

and started working


In my case the solution is the string itself

android.permission.READ_CONTACTS

I did Manifest.permission.READ_CONTACTS which caused silence error (Noting show on the screen).

Make sure that this is correct


I was doing two calls to requestPermissions(), one right after the other. This error message appeared in Logcat (note the misspelling on "request"):

Can reqeust only one set of permissions at a time

requestPermissions() is actually designed to take multiple requests at once; that's what the String array is for.


Change the final constant value to 1.

private static final int REQUEST_PERMISSION_WRITE = 1;

ActivityCompat.requestPermissions(this,new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},REQUEST_PERMISSION_WRITE);

참고URL : https://stackoverflow.com/questions/31878501/android-m-permission-dialog-not-showing

반응형