Upgrading android camera intent app to nougat (7.0+) replacing File://Uri with content://Uris

preview_player
Показать описание


For those of you who are using devices using android OS version 7.0 or later the camera intent application will fail. This is due to how android now enforces how files are shared from one application to another.
Applications now have to implicitly specify which files can be spared to other applications. This is done by creating a content:Uris which have temporary sharing permissions.
The android FileProvider is used to specify which files can have temporary sharable permissions applied to them.

Github details:

The code is now on github you can get it from here

or else run this command

In this tutorial we will cover:
- Adding the provider to the android manifest
- How to get the package name in the android manifest
- Adding meta-data to specify the files with shareable permissions
- Creating a filepaths xml file
- How to get the package name in source
- Creating a content:Uri using the FileProvider

API's covered:
- getApplicationContext().getPackageName()

Youtube playlist:

Website series:

Disclaimer - The only support provided on this channel which includes questions, will be submission of suspect bugs that are reproducible on android Nexus hardware on the github code base.

For much more information checkout
Рекомендации по теме
Комментарии
Автор

This provides a great tutorial for Android developers to go through. Just a reminder: check runtime permission for both camera and file storage

larrystreehouse
Автор

From a fellow Kiwi I just wanted to say thank you for this video, you should be the official Android tutor!! :)

haydo
Автор

Dude, u saved my life. I was trying to solve this problem for 2 days. This video and the video for marshmallow was awesome. Thank you so much.

umuttekin
Автор

great video :D
Not trying to be mean, but it's nice to find someone who doesn't have a super thick accent

pipicacadanslepot
Автор

You are my I almost gave up; but, I found you.

jbrian
Автор

like your tuts Nigel. keep them coming.

FouchimiLeBoss
Автор

Muchisimas gracias por ayudarme con este codigo, funciona perfecto!
Thank a lot by help me with this source code, it's work perfect

federicoCastiglione
Автор

Thanks, greetings from Argentina, it worked for me

EspinozaFederico
Автор

Thanks God it works now! Oh yeah! Thank you So much!

Zibo
Автор

Sir, how to create another directory in gallery in this project (not PICTURES)?

dedd
Автор

Hi Nigel. thanks for your tutorials. I used this video to upgrade my app, however the camera app (made after your
Android camera2 API - Part 12) does not write the image into the Uri that File Provider supplies. Can you help please?

RomanMedvid
Автор

Hi there I'm using a file provider for take a picture from the camera an save it in the internal storage and everything works fine but when I make a little change to the code for save it the image in the private files of my app the image not is saved, I getting private files with getFilesDir(), one thing more that only happen in android KitKat because un higer version I can save the image in the last directory and everything works fine, do you have some idea about that wat happen?

DjangoMx
Автор

I'm losing the will to live, I've been trying to take a picture and save it to the sd card for over a week with no luck. This seems to be the last piece of the puzzle but I get an error saying 'permission denied' when creating the temp file. I've never known something as difficult as developing for Android.

HapticAaron
Автор

Unfortunately, this doesn't work.

ulikulis
Автор

Hello Sir,
Here, Another Application means A Camera app that We are going to open to capture the image ??
Confused.
Are We providing our content URI to Camera App to use that file ??

thsimplifiedlearning
Автор

Can you explain why the path in file_paths.xml is "." ??

tungnguyen-uumk
Автор

After a tiresome 6 days of debugging I could manage to get error failed to find configured root that contains

vibinvarghese
Автор

Sir, you're not including <?xml version="1.0" encoding="utf-8"?> on filepaths.xml, is that runs well?

imma
Автор

Hi sir. I am developing with 7.1 currently. With these I am able to take photo and save it into memory.
The problem is that after capturing and save into storage, the gallery in my apps only shows previous photos and the latest one. For example, currently I have Photo X, Photo Y, and Photo Z in the in-app Gallery. If I capture 4 photos in a row WITHOUT restarting my device, the gallery shows only the latest 1 out of the 4 photos taken and Photo X, Y, and Z. I googled around and feel that something is wrong with 7.1. Btw I have already tried with sendBroadcast and MediaScannerConnection. Please help!

khchin
Автор

What do you mean by Versions of Android IOS?

thealpha_