Error in method getUriForFile - java.lang.IllegalArgumentException: Failed to find configured root that contains /storage/emulated/0/Android/data/ -


i've been working on simple android application takes picture , stores in app's directory. i've followed android developpers tutorials i'm still getting error.

i've seen lots of questions error in stackoverflow, none of them seen fix error.

this logcat error get:

    fatal exception: main process: com.example.victormaruca.gpstesting, pid: 31539 java.lang.illegalargumentexception: failed find configured root contains /storage/emulated/0/android/data/com.example.victormaruca.gpstesting/files/pictures/jpeg_20170914_014854_-551864997.jpg @ android.support.v4.content.fileprovider$simplepathstrategy.geturiforfile(fileprovider.java:712) @ android.support.v4.content.fileprovider.geturiforfile(fileprovider.java:401) @ com.example.victormaruca.gpstesting.mainactivity.dispatchtakepictureintent(mainactivity.java:124) @ com.example.victormaruca.gpstesting.mainactivity.access$000(mainactivity.java:43) @ com.example.victormaruca.gpstesting.mainactivity$3.onclick(mainactivity.java:81) @ android.view.view.performclick(view.java:5201) @ android.view.view$performclick.run(view.java:21163) @ android.os.handler.handlecallback(handler.java:746) @ android.os.handler.dispatchmessage(handler.java:95) @ android.os.looper.loop(looper.java:148) @ android.app.activitythread.main(activitythread.java:5443) @ java.lang.reflect.method.invoke(native method) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:728) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:618) 

this method call geturiforfile:

private void dispatchtakepictureintent() {     intent takepictureintent = new intent(mediastore.action_image_capture);      if (takepictureintent.resolveactivity(getpackagemanager()) != null) {          file photofile = null;         try {             photofile = createimagefile();         } catch (ioexception ex) {             log.e("erro", "no ceateimagefile() : "+ex);         }          if (photofile != null) {             uri photouri = fileprovider.geturiforfile(this,                     "com.example.victormaruca.gpstesting.fileprovider",                     photofile);             takepictureintent.putextra(mediastore.extra_output, photouri);             startactivityforresult(takepictureintent, request_take_photo);         }     } } 

and method create file:

private file createimagefile() throws ioexception {     // create image file name     string timestamp = new simpledateformat("yyyymmdd_hhmmss").format(new date());     string imagefilename = "jpeg_" + timestamp + "_";     file storagedir = getexternalfilesdir(environment.directory_pictures);     file image = file.createtempfile(             imagefilename,  /* prefix */             ".jpg",         /* suffix */             storagedir      /* directory */     );      // save file: path use action_view intents     mcurrentphotopath = image.getabsolutepath();     return image; } 

androidmanifest.xml snippet:

<application     android:allowbackup="true"     android:icon="@mipmap/ic_launcher"     android:label="@string/app_name"     android:roundicon="@mipmap/ic_launcher_round"     android:supportsrtl="true"     android:theme="@style/apptheme">     <activity android:name=".mainactivity">         <intent-filter>             <action android:name="android.intent.action.main" />              <category android:name="android.intent.category.launcher" />         </intent-filter>     </activity>      <provider         android:name="android.support.v4.content.fileprovider"         android:authorities="com.example.victormaruca.gpstesting.fileprovider"         android:exported="false"         android:granturipermissions="true">         <meta-data             android:name="android.support.file_provider_paths"             android:resource="@xml/file_paths"></meta-data>     </provider> </application>  <uses-permission android:name="android.permission.access_fine_location"/> <uses-permission android:name="android.permission.write_external_storage" />   <uses-feature   android:name="android.hardware.camera"                 android:required="true" /> 

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.example.victormaruca.gpstesting/files/pictures/" />     </paths> 

any apreciated!


Comments

Popular posts from this blog

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -

python - Error while using APScheduler: 'NoneType' object has no attribute 'now' -