12

ファイルプロバイダを使用して、指定された宛先に写真を保存しています。 私が取得:Androidファイルプロバイダ不正な引数例外

java.lang.IllegalArgumentExceptionが:android.support.FILE_PROVIDER_PATHSメタデータの欠落を カメラから画像を取り込むために活動を開くしようとしているとき。

マイManifest.xmlファイル:

<provider 
android:name="android.support.v4.content.FileProvider" 
android:authorities="com.example" 
android:exported="false" 
android:grantUriPermissions="true"> 
    <meta-data 
    android:name="android.support.FILE_PROVIDER_PATHS" 
    android:resource="@xml/paths" /> 
</provider> 

マイpaths.xmlファイル:

<paths xmlns:android="http://schemas.android.com/apk/res/android"> 
    <external-path name="content" path="Android/data/com.my_package_name/files/" /> 
</paths> 

とJavaコード:

File externalFilesDirectory = this.getExternalFilesDir(null); 
File imageFile = File.createTempFile(
     imageFileName, 
     ".jpg", 
     externalFilesDirectory 
); 
Uri photoURI = FileProvider.getUriForFile(this, "com.example", imageFile); 

最終行は例外を提供します。 私はここで何が欠けていますか?私は公式Android開発サイト(https://developer.android.com/training/camera/photobasics.html)からチュートリアルに従った

+0

チュートリアルのリンクを追加できますか? –

+0

うん、今すぐそれをした –

+0

'com.example'は' 'com.example" 'でなければなりません。それで解決しますか? –

答えて

15

私は解決策を見つけました。問題は、私の権限名が ".fileprovider"で終わらないということでした。一定。

+0

いいえ。それは奇妙な彼らはそれを実施すると思われる –

+0

FileProvider権限名が ".fileprovider"で終わらなければならないことを要求するドキュメントへのリンクを提供できますか? – anticafe

+0

https://developer.android.com/reference/android/support/v4/content/FileProvider.html#ProviderDefinition – Arst

関連する問題