无法读取android外部存储

时间:2019-08-14 16:07:27

标签: java android android-permissions

我需要在Android存储设备上阅读图片和视频,然后上传到S3。 我知道有人问过这个问题,但是我做了其他回答说的话,它仍然不起作用。这是s3方面的问题吗?

您可以在我的代码中看到,我在清单中添加了uses-permission语句,并在S3上传之前添加了内联权限请求

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

    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.READ_INTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".AddDpackActivity"></activity>
        <activity android:name=".Dpack_run" />

        <service android:name="org.eclipse.paho.android.service.MqttService" />
        <service android:name="com.amazonaws.mobileconnectors.s3.transferutility.TransferService" />


        <activity android:name=".SplashScreen">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".AuthenticationActivity"
            android:noHistory="true" />
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" />
    </application>

</manifest>


    if (photoPath != null) {

            if (ContextCompat.checkSelfPermission(this,
                    Manifest.permission.WRITE_EXTERNAL_STORAGE)
                    != PackageManager.PERMISSION_GRANTED && 
                    ContextCompat.checkSelfPermission(this,
                    Manifest.permission.READ_EXTERNAL_STORAGE)
                    != PackageManager.PERMISSION_GRANTED) {//Can add more as 
                    per requirement

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

            }

E/upload failed: Failed to upload photo. 
    com.amazonaws.AmazonClientException: Unable to calculate MD5 hash: /storage/emulated/0/Pictures/IMG_20190626_185712083.jpg: open failed: EACCES (Permission denied)

Caused by: java.io.FileNotFoundException: /storage/emulated/0/Pictures/IMG_20190626_185712083.jpg: open failed: EACCES (Permission denied)

Caused by: android.system.ErrnoException: open failed: EACCES (Permission denied)

0 个答案:

没有答案