Android:要求WRITE_EXTERNAL_STORAGE未显示的对话框

时间:2017-10-11 05:26:00

标签: android android-permissions

我有一个需要以下权限才能运行的Android应用程序。

ACCESS_FINE_LOCATION, ACCESS_WIFI_STATE, WRITE_EXTERNAL_STORAGE, RECORD_AUDIO

我的AndroidManifest.xml是:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:tools="http://schemas.android.com/tools"
          package="com.volkswagenits.passengerapp">

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.MEDIA_CONTENT_CONTROL" />
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
    <uses-permission android:name="com.google.android.gms.permission.ACTIVITY_RECOGNITION"/>


    <application
        ...
</manifest>

我的Splash活动是:

public class SplashActivity extends Activity {
    private static final String TAG = SplashActivity.class.getSimpleName();
    private static int SPLASH_TIME_OUT = 10000;
    private final int REQ_SOLVE_SERVICES_CODE = 15005;
    private int REQ_PERM_CODE = 1010;
    public static AudioInput AUDIO_INPUT;
    private static final String[] requiredPermissions = new String[] { ACCESS_FINE_LOCATION, ACCESS_WIFI_STATE, WRITE_EXTERNAL_STORAGE, RECORD_AUDIO};


    private void requestPermissionIfNeeded() {
        boolean allGranted = allPermissionsGranted(this, requiredPermissions);
        if (!allGranted) {
            ActivityCompat.requestPermissions(this,
                    requiredPermissions, REQ_PERM_CODE);
        } else {
            //If all permissions are granted, check that PlayServices are available
            checkPlayServices();
        }
    }

    private void initializeGlass() {

    }




    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        if (requestCode == REQ_PERM_CODE) {
            boolean allGranted = true;
            for (int result : grantResults) {
                if (result == PackageManager.PERMISSION_DENIED) {
                    allGranted = false;
                    break;
                }
            }
            if (!allGranted) {

            } else {
                //If all permissions are granted, check that PlayServices are available
                checkPlayServices();
            }
        }

    }


    private void checkPlayServices() {
        int status = GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(this);
        if (status != ConnectionResult.SUCCESS) {
            if (GoogleApiAvailability.getInstance().isUserResolvableError(status)) {
                GoogleApiAvailability.getInstance().getErrorDialog(this, status, REQ_SOLVE_SERVICES_CODE).show();
            } else {
                Toast.makeText(this, "Bus Sewa can not run without GoolgeServices.", Toast.LENGTH_SHORT).show();
                finish();
            }
        } else {
            bootGlasAndContinue();

        }
    }


}

授予所有权限的代码:

public static boolean allPermissionsGranted(Context context, String[] permissions) {
    for (String perm : permissions) {
        if (ContextCompat.checkSelfPermission(context, perm) == PackageManager.PERMISSION_DENIED) {
            return false;
        }
    }
    return true;
}

当应用程序启动时,它会请求访问精确位置的权限。它确实要求录制音频的许可。但是,它不会要求写入外部存储的权限。

我创建了一个小型演示应用程序。这段代码似乎在那里工作。 我错过了什么?

最终编辑:删除了不相关的代码。

2 个答案:

答案 0 :(得分:4)

问题的原因必须是使用gradle引入的外部库,gradle有自己的清单请求类似这样的内容

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

因此,在应用清单文件中,您需要添加此类权限

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

这会覆盖其他应用程序HockeyApp在您的情况下设置的权限

答案 1 :(得分:0)

有效:

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

曲棍球应用程序是一个问题。