ベストソリューションです:FileProvider(サポートライブラリ-V4を必要とする) それは内部ストレージを使用しています! https://developer.android.com/reference/android/support/v4/content/FileProvider.html
Application要素にマニフェストであなたのFileProviderを定義します。
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="your.package.name.fileprovider"
android:exported="false"
android:grantUriPermissions="true" >
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/image_path" />
</provider>
は、マニフェストのルート要素に権限を追加します。
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" android:required="false" />
は/例えば解像度であなたのイメージのパスを定義xml/image_path.xml:
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<files-path name="captured_image" path="your/path/"/>
</paths>
のJava:
private static final int IMAGE_REQUEST_CODE = 1;
// your authority, must be the same as in your manifest file
private static final String CAPTURE_IMAGE_FILE_PROVIDER = "your.package.name.fileprovider";
4.1キャプチャ意図:
File path = new File(activity.getFilesDir(), "your/path");
if (!path.exists()) path.mkdirs();
File image = new File(path, "image.jpg");
Uri imageUri = FileProvider.getUriForFile(activity, CAPTURE_IMAGE_FILE_PROVIDER, image);
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
startActivityForResult(intent, IMAGE_REQUEST_CODE);
4.2 onActivityResult():
@Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (requestCode == IMAGE_REQUEST_CODE) {
if (resultCode == Activity.RESULT_OK) {
File path = new File(getFilesDir(), "your/path");
if (!path.exists()) path.mkdirs();
File imageFile = new File(path, "image.jpg");
// use imageFile to open your image
}
}
super.onActivityResult(requestCode, resultCode, intent);
}
グレートは、私が問題だった予感がありました。私はちょうどSDカードに一時的に写真を保存する移動するつもりだと思いますが、私はこれを私のツールキットに追加します:) – sgarman
Context.MODE_WORLD_WRITEABLE廃止を解決する方法に関するアイデアはありますか? – superbre
ここから(http://developer.android.com/reference/android/content/Context.html):** MODE_WORLD_WRITEABLEこの定数は、APIレベル17では非推奨です。書き込み可能なファイルを作成することは非常に危険であり、アプリケーションにセキュリティホールを生じさせます。** – Atul