Android FileProvider Causing Camera/Gallery to Crash at Random -


goodday.

using gotten developers guide, able app's photo capture working. activity involves capturing 1 or more images(something in photogrid camera collage app). works of time, , on devices, except on own device(android 5.0.1). issue is, camera/gallery app crashes, giving me security permission denial error in stack trace, , i've searched solutions , implemented them, no avail. crash random, more occur when: 1. i'm taking second photo 2. camera settings on highest resolution :13mp (hardly ever happens on lower resolutions)

it occurs in other cases though, occurrence drives me crazy. here's code:

fragment

    private void dispatchtakepictureintent(boolean isquestionimage) {             intent takepictureintent = new intent(android.provider.mediastore.action_image_capture);              if (takepictureintent.resolveactivity(getactivity().getpackagemanager()) != null) {                  file photofile = null;                 try {                     photofile = createimagefile(isquestionimage);                 } catch (ioexception ex) {                     log.e("photofile part", "error: "+ex);                 }                  if (photofile != null) {                     uri photouri = fileprovider.geturiforfile(getactivity(),                             "com.operator.u_learn.fileprovider", photofile);                      if (build.version.sdk_int>=build.version_codes.lollipop) {                         takepictureintent.addflags(intent.flag_grant_write_uri_permission);                         takepictureintent.addflags(intent.flag_grant_read_uri_permission);                      }                     if(build.version.sdk_int <= build.version_codes.kitkat) {                         list<resolveinfo> resolvedintentactivities = getactivity()                                 .getpackagemanager()                                 .queryintentactivities(takepictureintent, packagemanager.match_default_only);                            (resolveinfo resolvedintentinfo : resolvedintentactivities) {                                string packagename = resolvedintentinfo.activityinfo.packagename;                                  getactivity().granturipermission(packagename,                                     photouri,                      intent.flag_grant_write_uri_permission | intent.flag_grant_read_uri_permission);                         }                     }                      takepictureintent.putextra(mediastore.extra_output, photouri);                      if(isquestionimage)                         startactivityforresult(takepictureintent, request_question_image_capture);                     else                         startactivityforresult(takepictureintent, request_explanation_image_capture);                      //revoke permissions after use                     if(build.version.sdk_int <= build.version_codes.kitkat) {                         getactivity().revokeuripermission(photouri, intent.flag_grant_read_uri_permission);                     }                  }             }         } 

androidmanifest.xml

<provider   android:name="android.support.v4.content.fileprovider"   android:authorities="com.operator.u_learn.fileprovider"             android:exported="false"             android:granturipermissions="true">             <meta-data   android:name="android.support.file_provider_paths"                 android:resource="@xml/file_paths"></meta-  data>         </provider> 

file_paths.xml

<?xml version="1.0" encoding="utf-8"?> <paths   xmlns:android="http://schemas.android.com/apk/res/android">     <external-path name="my_images"   path="android/data/com.operator.u_learn/files/pictures" /> </paths> 

and here's error get

e/androidruntime: fatal exception: main                                                    process:   com.android.gallery3d, pid: 18974   java.lang.securityexception: permission denial: opening   provider android.support.v4.content.fileprovider   processrecord{3b596555 18974:com.android.gallery3d/u0a42}   (pid=18974, uid=10042) not exported uid 10221                                                        @   android.os.parcel.readexception(parcel.java:1540)                                                        @   android.os.parcel.readexception(parcel.java:1493) 

in experience, camera module locked previous activity. can check running preview camera app , switching camera app preview screen.

possibly, highest resolution make occur more requires more time released.

as know, there several different implementations in android devices among manufacturers+hardware+camera driver+os+manufacturer's default camera app combination. allow camera api accessed releasing previous accessed app automatically (lg nexus 5), while others crashed (lg g2 phone).

to fix problem, if diagnostics correct, recommend add sleep counter thread.sleep(500); before launching it.

or, try-catch camera.open() method. give runtimeexception if locked other processor. in experience, camera api unreliable make wrap try-catch codes @ every line of api commands.

though answer cannot solution gallery crash issue, camera be.


Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -