READ_EXTERNAL_STORAGE cannot be resolved or is not a field - android

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.

Related

Failed to Save Files on Storage [FileSystemException] Flutter

I uploaded an android photo compress application in play store and I checked every thing is ok, but some users have issue that the application can not save compressed photos, I checked that and I found this error
[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: FileSystemException: Cannot create file, path = '/storage/emulated/0/My Folder/photo.jpg' (OS Error: Operation not permitted, errno = 1)
This is permissions AndroidManifest.xml
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_MEDIA_LOCATION"/>
<uses-permission android:name="android.permission.CAMERA"/>
This line inside application tag
android:requestLegacyExternalStorage="true"
I looked for some solutions and founded this permission line
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"
tools:ignore="ScopedStorage" />
But when ask for this permission android shows to user warning the application will access to all files without asking permission, I feel this is worrying for users and some may be afraid of this permission, however I uploaded the application but it was rejected because using MANAGE_EXTERNAL_STORAGE permission.
you are right regarding MANAGE_EXTERNAL_STORAGE permission. Your app will be removed from play store if you don't have valid reasons. You may have to create a video and explain why you need these permission, and how scoped storage can't help you.
Now, you should know one thing that you are trying to create a folder directly inside internal storage. This will work in lower android versions but will fail in Android 10 or above even when you have WRITE_EXTERNAL_STORAGE granted.
Try creating your files inside public directories like Download or Documents. If the files downloaded doesn't need to be accessed by users then you can always save in your package folder context.getExternalFilesDir(null)
Hope this helped you! If you have any further doubts feel free to comment down below.

What permission to be added in app.json for CAMERA_ROLL in app.json for Android?

In my Application I'm using expo-image-picker to pick image to update the user's profile picture.
I had done the implementation. while implementing I used CAMERA_ROLL as type to check the permissions for Gallery.
By Default Expo is includes all permissions link. I don't need that. I need to use only CAMER_ROLL as permission. I went through the app.json configuration docs but there, I can't find CAMER_ROLL or GALLERY related permissions.
What permission to be added in app.json for CAMERA_ROLL ?
You need to add these permissions to your AndroidManifest.xml file.
<uses-permission android:name="android.permission.MANAGE_DOCUMENTS" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
I also had similar scenario. CAMERA_ROLL permission is all about reading and writing to the storage memory. So, it requires below Android permission needs to be added in app.json
READ_EXTERNAL_STORAGE
WRITE_EXTERNAL_STORAGE

What else do I need to do in order to write to an android device folder?

Here is my code: using Xamarin in MainActivity.cs
It will say access denied.
I've check write & read external, coarse & find access, and some more accesses.
What else am I missing?
var s = Path.Combine(Android.OS.Environment.DirectoryDocuments.ToString(), "test.txt");
You need to declare WRITE_STORAGE_PERMISSION in your menifest.xml file.
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
If your target SDK Version is greater then 23 then you need to Request app permissions on runtime.
https://developer.android.com/training/permissions/requesting#java

How to ask for Photos/Media/Files permission in android app

enter image description here
I want my app to ask for Photos/Media/Files permission since a third party library requires it, can anyone tell me which specific permission to ask for.
Thanks
Files, photos and media are saved in storage. Your android app will request permission in the relation of what it requires to do. Add the permissions in your Manifest file.
The permission you require is:
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
If you want to save Files with your app too, request:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Android versions from Marshmallow and above require runtime grant of permissions. Run the following
String[] PERMISSIONS = {
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.READ_EXTERNAL_STORAGE
};
ActivityCompat.requestPermissions(this,
PERMISSIONS,
PERMISSION_REQUEST_READ_FOLDERS);

Asking for PACKAGE_USER_STATS authorization

I'm trying to ask an authorization for devices with API >= 23 to check package user stats.
As stated in https://developer.android.com/about/versions/android-5.0.html#System, I can use the android.app.usage API.
The usage of that API requires that I declare in the manifest this permission:
<uses-permission android:name="android.permission.PACKAGE_USAGE_STATS" tools:ignore="ProtectedPermissions" />
But if I don't "ignore ProtectedPermissions", AndroidStudio gives me this error:
The questions:
does this mean that, how stated in the documentation, The user must also enable access for this app through Settings > Security > Apps with usage access., or the two things are not related to eachothers?
How do I ask to the user to enable access for this app through Settings > Security > Apps with usage access. anyway?
And anyway, why, when I manually set to on the app in Settings > Security > Apps, bypassing the previous point, I still don't get the dialog when I reach this lines of code, the authorization still is not given? This is exactly what the Android Documentation seems to ask to do. Why this request doesn't even popup? What else is missing?
if (Build.VERSION.SDK_INT >= 23)
if (ContextCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.PACKAGE_USAGE_STATS) != PackageManager.PERMISSION_GRANTED)
ActivityCompat.requestPermissions(myActivity, new String[]{Manifest.permission.PACKAGE_USAGE_STATS}, MY_REQUEST_CODE); // <-- I reach this point but the dialog does not popup!??
You should set permission like that;
<uses-permission
android:name="android.permission.PACKAGE_USAGE_STATS"
tools:ignore="ProtectedPermissions" />
And you can access permission as below;
Intent intent = new
Intent(android.provider.Settings.ACTION_USAGE_ACCESS_SETTINGS);
startActivity(intent);
Hope, it helps.

Categories

Resources