I used default camera of device for capture photo in my app. When I used android 10 and below version everything is working fine. but when I used camera in android 11 then not working in app. Can you help me to solve this problem.
Open Image Capture. In the sidebar, click on your Android device. Choose the folder where you want to save your pictures using the drop-down menu. Then, select the images you want to transfer and click Download.
Since API level 30, there have been changes in the package visibility. https://developer.android.com/about/versions/11/privacy/package-visibility
For your package manager to work properly, you need to declare <queries>
in your AndroidManifest.xml
:
Code:
<manifest package="your.package.name">
<queries>
<intent>
<action android:name="android.media.action.IMAGE_CAPTURE" />
</intent>
</queries>
</manifest>
This works only for the default camera apps. If your app is using some 3rd party camera, you can find some info here.
You need to change
File sd_directory = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
to
File sd_directory = getExternalFilesDir(Environment.DIRECTORY_PICTURES);
Android 11 has Storage update. So When using SDK >= 29 must set URI instead of File path.
URI uri = null; // set this uri in camera Intent
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED))
{
uri = getApplicationContext().getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, new ContentValues());
}
else
{
uri = getApplicationContext().getContentResolver().insert(MediaStore.Images.Media.INTERNAL_CONTENT_URI, new ContentValues());
}
}
Since API level 30, there have been changes in the package visibility. https://developer.android.com/about/versions/11/privacy/package-visibility
For your package manager to work properly, you need to declare <queries>
in your AndroidManifest.xml
:
Code:
<manifest package="your.package.name">
<queries>
<intent>
<action android:name="android.media.action.IMAGE_CAPTURE" />
</intent>
</queries>
</manifest>
This works only for the default camera apps. If your app is using some 3rd party camera, you can find some info here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With