简体   繁体   中英

READ_EXTERNAL_STORAGE cannot be resolved or is not a field

I'm trying to republish my app for API level 26 as per Play Store requirements but I am getting null back from this:

File[] files = directory.listFiles();

I understand this is because I need to check permissions at runtime now. I have inserted this code at the start of the activity's onCreate to do that.

// check permissions
    if (ContextCompat.checkSelfPermission(this, android.Manifest.permission.READ_EXTERNAL_STORAGE)
            != PackageManager.PERMISSION_GRANTED)
    {
        // Permission is not granted
        this.finish();
    }

But it does not recognise READ_EXTERNAL_STORAGE. Strangely it does recognise WRITE_EXTERNAL_STORAGE. I saw many responses saying the wrong import is to blame, so I now have this:

import android.Manifest;

In the manifest itself I have this, inside the Manifest tag but outside the Application tag.

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

I am working in Eclipse/ADT and have updated the SDK and support package. Any idea what is going on here?

I had not updated the build target in the Project Properties. If anyone else faces this situation that is the solution.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM