gpt4 book ai didi

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

转载 作者:搜寻专家 更新时间:2023-11-01 08:24:27 27 4
gpt4 key购买 nike

我有一个 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 Activity 是:

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;
}

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

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

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

最佳答案

问题的原因一定是使用 gradle 引入的外部库,它有自己的 list 请求这样的东西

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

所以在应用程序 list 文件中你需要像这样放置一个权限

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

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

关于Android:未显示要求 WRITE_EXTERNAL_STORAGE 的对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46680461/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com