requestPermissions未在设备上显示权限对话框,在Android工作室模拟器上运行良好

时间:2016-07-07 12:14:49

标签: android

面对使用requestPermissions活动方法的奇怪问题。它现在显示我是否在设备上调试。如果我在Android工作室模拟器上调试应用程序,效果很好。 以下是请求许可的代码。

    2016-07-07 07:46:42,240 Trac[web_ui] DEBUG: RPC incoming request of content type 'text/xml' dispatched to <tracrpc.xml_rpc.XmlRpcProtocol object at 0x03D3E630>
    2016-07-07 07:46:42,240 Trac[web_ui] DEBUG: RPC(XML-RPC) call by 'user'
    2016-07-07 07:46:42,240 Trac[xml_rpc] DEBUG: RPC(xml) call by 'user', method 'ticket.query' with args: ('max=0&status!=closed',)
    2016-07-07 07:46:42,240 Trac[web_ui] DEBUG: RPC(XML-RPC) call by 'user' ticket.query
    2016-07-07 07:46:42,240 Trac[query] DEBUG: Count results in Query: 4
    2016-07-07 07:46:42,240 Trac[xml_rpc] DEBUG: RPC(xml) 'ticket.query' result: []

这是AndroidManifest

public boolean isStoragePermissionGranted() {
        if (Build.VERSION.SDK_INT >= 23) {
            if (checkSelfPermission(android.Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED ) {
                return true;
            } else {
                    requestPermissions(new String[]{android.Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1);
                return false;
            }
        } else { //permission is automatically granted on sdk<23 upon installation
            return true;
        }
    }

和build.gradle

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

运行调试的设备是OnePlus 1.我错过了什么吗?

以下是尝试requestPermissions时的一些其他日志:

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.3"

    defaultConfig {
        applicationId "abc.xyz"
        minSdkVersion 23
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

1 个答案:

答案 0 :(得分:1)

更改

requestPermissions(new String[]{android.Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1);

TO

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

https://stackoverflow.com/a/33162451/3142192