2016-09-02 5 views
2

を含む設定済みのルートを見つけることができませんでした。私はGoogleのトレーニングセクション "Taking photos simply"を使用しようとしています。写真を撮って保存する: "IllegalArgumentException:"

static final int REQUEST_TAKE_PHOTO = 1; 
private String mCurrentPhotoPath; 

protected void takeAPic() { 

    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 
    // Ensure that there's a camera activity to handle the intent 
    if (takePictureIntent.resolveActivity(getPackageManager()) != null) { 
     // Create the File where the photo should go 
     File photoFile = null; 
     try { 
      photoFile = createImageFile(); 
     } catch (IOException ex) { 
      // Error occurred while creating the File 
      ex.printStackTrace(); 

     } 
     // Continue only if the File was successfully created 
     if (photoFile != null) { 
      Uri photoURI = FileProvider.getUriForFile(this, // here the exception is triggered. 
        BuildConfig.APPLICATION_ID + ".fileprovider", 
        photoFile); 
      takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI); 
      startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO); 
     } 
    } 

} 


private File createImageFile() throws IOException { 
    // Create an image file name 
    String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); 
    String imageFileName = presenter.getGtin() + "-" + timeStamp; 
    File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES); 
    File image = File.createTempFile(
      imageFileName, /* prefix */ 
      ".jpg",   /* suffix */ 
      storageDir  /* directory */ 
    ); 

    // Save a file: path for use with ACTION_VIEW intents 
    mCurrentPhotoPath = "file:" + image.getAbsolutePath(); 
    return image; 
} 
:写真を撮る

<?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/${applicationId}/files/Pictures" /> 
</paths> 

:file_paths.xmlで

// inside application tag 
    <provider 
     android:name="android.support.v4.content.FileProvider" 
     android:authorities="${applicationId}.fileprovider" 
     android:exported="false" 
     android:grantUriPermissions="true"> 
     <meta-data 
      android:name="android.support.FILE_PROVIDER_PATHS" 
      android:resource="@xml/file_paths"/> 
    </provider> 

:マニフェストで

:私は私のプロジェクトに関連するデータを変更し、コードをコピーしました

例外:

java.lang.IllegalArgumentException: Failed to find configured root that contains /storage/emulated/0/Android/data/my.package.name/files/Pictures/8712561249140-20160902_104505516416962.jpg 
       at android.support.v4.content.FileProvider$SimplePathStrategy.getUriForFile(FileProvider.java:679) 
       at android.support.v4.content.FileProvider.getUriForFile(FileProvider.java:378) 
       at my.package.name.usecases.reviewdata.ReviewDataActivity.takeAPic(ReviewDataActivity.java:242) 
       at my.package.name.usecases.reviewdata.ReviewDataActivity.onOptionsItemSelected(ReviewDataActivity.java:118) 
       at android.app.Activity.onMenuItemSelected(Activity.java:2885) 
       at android.support.v4.app.FragmentActivity.onMenuItemSelected(FragmentActivity.java:421) 
       at android.support.v7.app.AppCompatActivity.onMenuItemSelected(AppCompatActivity.java:188) 
       at android.support.v7.view.WindowCallbackWrapper.onMenuItemSelected(WindowCallbackWrapper.java:103) 
       at android.support.v7.view.WindowCallbackWrapper.onMenuItemSelected(WindowCallbackWrapper.java:103) 
       at android.support.v7.app.ToolbarActionBar$2.onMenuItemClick(ToolbarActionBar.java:69) 
       at android.support.v7.widget.Toolbar$1.onMenuItemClick(Toolbar.java:202) 
       at android.support.v7.widget.ActionMenuView$MenuBuilderCallback.onMenuItemSelected(ActionMenuView.java:761) 
       at android.support.v7.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:810) 
       at android.support.v7.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:152) 
       at android.support.v7.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:957) 
       at android.support.v7.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:947) 
       at android.support.v7.widget.ActionMenuView.invokeItem(ActionMenuView.java:618) 
       at android.support.v7.view.menu.ActionMenuItemView.onClick(ActionMenuItemView.java:155) 
       at android.view.View.performClick(View.java:4789) 
       at android.view.View$PerformClick.run(View.java:19881) 
       at android.os.Handler.handleCallback(Handler.java:739) 
       at android.os.Handler.dispatchMessage(Handler.java:95) 
       at android.os.Looper.loop(Looper.java:135) 
       at android.app.ActivityThread.main(ActivityThread.java:5294) 
       at java.lang.reflect.Method.invoke(Native Method) 
       at java.lang.reflect.Method.invoke(Method.java:372) 
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904) 
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699) 

私はここで検索しましたが、別のケースであったため、答えが役に立たなかった。私は間違っているの?私はプロジェクトをきれいにし、アンインストールして、gradleの値ではなくappIDを試してみてください。

ありがとうございます!

9月5日更新:私はそれを妨害していないことを確認するために新しいプロジェクトを作成しました。同じエラー、同じ結果を持つ別の携帯電話とエミュレータも試しました。

+1

'ReviewDataActivity.javaには何があります:242'? –

+0

@IshitaSinhaそれは失敗している関数への呼び出しです: 'Uri photoURI = FileProvider.getUriForFile(this、BuildConfig.APPLICATION_ID +" .fileprovider "、photoFile); '私の元の質問のコードにも含まれています。 – AlbertoGarrido

+0

私は同じ問題を抱えていて、それはナッツを運転しています。あなたは解決策を見つけましたか? – CYMA

答えて

0

パスの値は相対的であることができます。

<?xml version="1.0" encoding="utf-8"?> 
<paths xmlns:android="http://schemas.android.com/apk/res/android"> 
    <external-path name="my_images" path="Pictures/" /> 
</paths> 
関連する問題