0
I have a project that there is a form that the user can take a photo to insert, this worked but due to an android update whenever I click the photo button the app to, someone knows what can be?
E/AndroidRuntime: FATAL EXCEPTION: main
Process: clients.ravero.net.jgpforms, PID: 13356
android.os.FileUriExposedException: file:///storage/emulated/0/Pictures/JPEG_20180315_124134_131115397.jpg exposed beyond app through ClipData.Item.getUri()
at android.os.StrictMode.onFileUriExposed(StrictMode.java:1799)
at android.net.Uri.checkFileUriExposed(Uri.java:2346)
at android.content.ClipData.prepareToLeaveProcess(ClipData.java:832)
at android.content.Intent.prepareToLeaveProcess(Intent.java:9514)
at android.content.Intent.prepareToLeaveProcess(Intent.java:9499)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1644)
at android.app.Activity.startActivityForResult(Activity.java:5037)
at android.app.Activity.startActivityFromFragment(Activity.java:5023)
at android.app.Activity$HostCallbacks.onStartActivityFromFragment(Activity.java:7507)
at android.app.Fragment.startActivityForResult(Fragment.java:1150)
at android.app.Fragment.startActivityForResult(Fragment.java:1139)
at clients.ravero.net.jgpforms.fragments.FormFragmentBase.startTakePicture(FormFragmentBase.java:275)
at clients.ravero.net.jgpforms.fragments.FormFloraArvoresIsoladasFragment$3.onClick(FormFloraArvoresIsoladasFragment.java:294)
at android.view.View.performClick(View.java:6257)
at android.widget.TextView.performClick(TextView.java:11149)
at android.view.View$PerformClick.run(View.java:23705)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6780)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1496)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1386)
manifest
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.FLASHLIGHT" />
<uses-feature android:name="android.hardware.camera"/>
<uses-feature android:name="android.hardware.camera.flash"/>
<uses-feature android:name="android.hardware.camera2" />
method
@Override
public void startTakePicture(int requestCode) {
int finalRequestCode = requestCode + REQUEST_CODE_TAKE_PICTURE_BASE;
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePictureIntent.resolveActivity(getActivity().getPackageManager()) != null) {
try {
mPhotoFile = createImageFile();
} catch (IOException ex) {
ex.printStackTrace();
return;
}
// Continue only if the file was created
if (mPhotoFile != null) {
mPhotoFileUri = Uri.fromFile(mPhotoFile);
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, mPhotoFileUri);
startActivityForResult(takePictureIntent, finalRequestCode);
}
}
}
You added permission to the manifest ?
– rbz
In emulator happens the same thing ? Logcat presents some error ? It would be interesting to put the previous version of android and current version.
– Viktor Hugo
See if it’s something like: https://answall.com/questions/203465/permiss%C3%A3o-de-c%C3%A2mera-no-android
– rbz
added the manifest and personal errors
– Henrique Rodrigues
Put the method you are running...
– rbz
From API 24, android considers a serious security failure to display uris that relate to files (file://). Then, whenever you propagate an Internet through the system with such a Library, you will receive a Fileuriexposedexception in response. The solution is to create a specialized content Provider for this situation. It is called File Provider. The tense that became annoying to implement in the new way.
– Viktor Hugo
Help yourself: https://stackoverflow.com/questions/41144898/android-camera-intent-fileuriexposedexception-for-sdk-24
– Viktor Hugo