2017-10-31 22 views
-3

Android Nで自分のアプリでカメラを動作させただけで、カメラで画像を撮ってOKをクリックすると、編集する写真がありません。ps: 'my appフォトエディタ」であり、ここで iはコードで行った変更です:。FileUriExposedExceptionアンドロイドN以降

だった:

private Uri getImageUri() { 
    File file = new File(Environment.getExternalStorageDirectory().getPath(), fname); 
    Uri tempURI = Uri.fromFile(file); 
    Log.e("URI", ">> " + tempURI); 
    return tempURI; 
} 

がなる:

private Uri getImageUri() { 
    File file = new File(Environment.getExternalStorageDirectory().getPath(), fname); 
    Uri tempURI = GenericFileProvider.getUriForFile(getApplicationContext(), getApplicationContext().getPackageName() + ".provider", file); 
    //Uri tempURI = Uri.fromFile(file); 
    Log.e("URI", ">> " + tempURI); 
    return tempURI; 
} 

と、この:

case R.id.ic_camera: 
    // root = this.getCacheDir(); 
    galleryopen = true; 
    fname = "Style" + System.currentTimeMillis() + ".jpg"; 

    Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); 
    cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, getImageUri()); 
    startActivityForResult(cameraIntent, SELECT_CAMERA); 
    break; 

へ:

case R.id.ic_camera: 
    // root = this.getCacheDir(); 
    galleryopen = true; 
    fname = "Style" + System.currentTimeMillis() + ".jpg"; 

    Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); 
    cameraIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); 
    cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, getImageUri()); 
    startActivityForResult(cameraIntent, SELECT_CAMERA); 
    break; 

と私は、私が行方不明ですかわからない、私はあなたの助けに感謝します、アンドロイド7ファイルのURI以来およそのAndroid 5.1、最終的にはあるので、あなたに

答えて

0

に感謝推奨されません。代わりに、fileproviderを使用してコンテンツuriを使用する必要があります。 https://developer.android.com/reference/android/support/v4/content/FileProvider.html

とコンテンツURIまたは単に長期FileUriExposedExceptionを検索しますが、他のstackoverflowのスレッドでいくつかの良い説明を見つけることができます:

はそれについての詳細を調べるためにFileProviderのマニュアルを参照してください。