本文介绍了定位android O之后如何读取和写入外部存储(26)8.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 在定位下面的Android O代码之前,效果很好。设置targetApi = 27(8.1)后,此操作停止工作。Before targetting android O code below worked perfectly. After setting targetApi=27 (8.1) this stopped working.context.requestPermissions(new String[]{ Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE}, requestCode);我看到了一个众所周知的权限对话框,很高兴允许App访问照片媒体和文件I am presented with a permission dialog we all know, I gladly allow App to access photos media and files on a device.并在 onRequestPermissionResult()中返回android.permission.READ_EXTERNAL_STORAGE == 0,android.permission.WRITE_EXTERNAL_STORAGE == -1我遵循了这个答案 https://stackoverflow.com/a/48353465/ 4858147 无法正常工作。I followed this answer https://stackoverflow.com/a/48353465/4858147 didn't work.我在寻找解决方案时,发现了 https://developer.android.com/about/versions/oreo/android-8.0-changes.html#rmp 阅读此书后我并不聪明,但我100%确信这是造成这种情况的原因。While I was looking for a solution, found this https://developer.android.com/about/versions/oreo/android-8.0-changes.html#rmp I wasn't cleverer after reading this, but I am 100% sure this is causing it.我尝试只请求读取权限( dialog-> allow ),后来又请求写入权限(没有对话框->仍未授予)它不起作用。I tried asking only for read permission (dialog-> allow) and later I asked for write permission (no dialog -> still not granted) it didn't work.清单:<!-- Internet Permissions --><uses-permission android:name="android.permission.INTERNET" /><uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /><!-- I added now, --><uses-permission android:name="android.permission.CAMERA"/><!-- Storage Permissions --><uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /><uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /><!-- Account Access Permission --><uses-permission android:name="android.permission.GET_ACCOUNTS" /><!-- Vibrate used for notification updates --><uses-permission android:name="android.permission.VIBRATE" />我需要对此权限Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");intent.putExtra("output", outputDestination);推荐答案好吧,在阅读 https://stackoverflow.com/a/49709872/4858147 我终于能够继续。Okay so I finally know what's happening, after reading https://stackoverflow.com/a/49709872/4858147 I was finally able to continue.问题是HockeyApp出现在清单中:Problem was that HockeyApp had in manifest:<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="18" />清单合并后,应用程序中没有WRITE_EXTERNAL_STORAGE权限。and after manifests were merged there was no WRITE_EXTERNAL_STORAGE permission in app. The app worked before thanks to a bug in an android system在Android系统中出现错误之前就可以使用了,因为我们要求读取权限It worked before thanks to bug in Android system, because we asked for read permission我所做的就是在我的主应用清单中更改了All I did was that in my main App manifest I changed <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" tools:remove="android:maxSdkVersion" /> 这篇关于定位android O之后如何读取和写入外部存储(26)8.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!