Android target sdk 33, READ_MEDIA_VIDEO not working - android

I have requested below two permissions in app,
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO " />
Then I allow the permissions, and verify from 'App permissions'
But, the app still dont have the READ_MEDIA_VIDEO permission, e.g the below code return false. And the app cannot access/read the videos from device.
ContextCompat.checkSelfPermission(
context!!,
Manifest.permission.READ_MEDIA_VIDEO
) == PackageManager.PERMISSION_GRANTED

If your app only needs to access images, photos, and videos, consider using the photo picker instead of declaring the READ_MEDIA_IMAGES and READ_MEDIA_VIDEO permissions.
More details available here
According to Google storage documentation. It seems that for non-media files no permission is needed.

Related

Unresolved reference: READ_MEDIA_IMAGES

I started targeting Android 13 with API 33. The app is requesting Manifest.permission.READ_EXTERNAL_STORAGE for the older APIs. Now I know that I have to request the new permissions: READ_MEDIA_IMAGES and READ_MEDIA_VIDEO.
I have added in the manifest:
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
and now, as a result, in the setting of the permissions for the app I see an extra option to enable these permissions.
What I can't do is to ask the permission at runtime
If I try to access Manifest.permission.READ_MEDIA_IMAGES in the code I get unresolved reference so I can't dynamically request the permission and if I don't then the user needs to do it manually.
How to handle the READ_MEDIA_IMAGES and READ_MEDIA_VIDEO?
According to official documentation https://developer.android.com/about/versions/13/behavior-changes-13#granular-media-permissions, you should ask permission in runtime.
Also notice:
Note: If your app only needs to access images, photos, and videos, consider using the photo picker instead of declaring the READ_MEDIA_IMAGES and READ_MEDIA_VIDEO permissions.

Android API 28, save file in Download folder without user interaction

we're developping an app that will run as a service. One of the feature would be to download file at given URL (ex PDF) and save it into the download folder so user can load it from a specific application (Avenza Maps).
All the download process should be without any user interaction since it's by a service that run in the background.
i've added the following permission:
AndroidManifest.xml
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"/>
<application
android:requestLegacyExternalStorage="true"
whatever i'll try i got the following error
java.io.FileNotFoundException: /storage/emulated/0/Download/name.pdf (Permission denied)
how can i get the permission to write on Download folder (this is system Download folder)
without having to open an activity to save the file?
i'll try multiple solution yet(2 day of google) without success
for now as stated we target API 28 (android 9)
we will later target other API since we provide the device to the client so we develop only for the API our device have.
I've recently had to develop an app that downloads voice files to a device. While you can specify permissions in the Android manifest, you must request permissions from the user. I've done so in Java, but a conversion to Kotlin should be simple.
//method is called to check the storage permissions for this app
//ensures the app can write and read files
private void checkStoragePermissions() {
Log.i("Permissions", "Checking Storage Permissions");
int writePermissionCode = ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE);//get current write permission
int readPermissionCode = ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE);//ge current read permission
Log.i("Permissions", "Fetching Read & Write Codes: " + readPermissionCode + "/" + writePermissionCode);
//if permissions to read and write to external storage is not granted
if (writePermissionCode != PackageManager.PERMISSION_GRANTED || readPermissionCode != PackageManager.PERMISSION_GRANTED) {
//request read and write permissions
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, PackageManager.PERMISSION_GRANTED);
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, PackageManager.PERMISSION_GRANTED);
Log.i("Permissions", "Asking For Storage Permissions");
} else {//else: if permissions to read and write is already granted
permissionsGranted = true;//set permissions granted bool to true
}
}
After you've done this the downloading of the files can be done in many ways. It's worth noting that files can't be downloaded to any location on an Android device. Only a specific destinations can be used.
I hope this helps to clear some of your confusion. Happy coding!
how can i get the permission to write on Download folder (this is system Download folder) without having to open an activity to save the file?
The simplest solution is to write somewhere else, where you do not need permissions. The methods on Context that return File objects, like getFilesDir() and getExternalFilesDir(), are your primary candidates.
Beyond that, it appears that your app is pre-installed on some device ("we provide the device to the client"). If you have developed a custom firmware image, you should be able to pre-grant the permission to your app as part of that image. Or, if the device is being distributed already configured (no first-time-power-on onboarding UI), you could manually grant WRITE_EXTERNAL_STORAGE to your app or have a UI automation script do it.
If none of those are options, then you have no choice but to ask the user for permission.

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.

Camera permissions are not requested but are still working

Manifest file:
<uses-permission android:name="android.permission.CAMERA" android:requiredFeature="true" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:requiredFeature="true" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" android:requiredFeature="true"/>
The app does not request the camera permissions but it is still working.
I am able to use the camera using the following intent:
val takePhotoIntent = Intent(MediaStore.ACTION_IMAGE_CAPTURE)
I am not sure why.
This is despite the fact that no permissions are granted to the app:
The reason this works is that your app is not getting access to any of:
The camera itself
The user's internal/external storage
The user's existing photos
All you're getting is the opportunity to ask the user to take a photo and return that photo to you. Because the user needs to affirmatively consent as part of the process, no permission is required.
This model also has the benefit of allowing apps to capture photos even if the user would not entrust them with camera or storage permissions. They can rest assured that the app only got access to the single photo that the user took. The same principle applies when asking the user to select a photo as well.
I think this is because you're not actually getting control of the camera yourself. You're asking to launch the camera app. There's no way in this for your app to take a photo without user intervention, so it's safe.
It's maybe because you are running it on an older api or have already gave these privileges to the app for once. The other possibility: your device is rooted.

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

Categories

Resources