2
我用下面的代碼,以我的應用程序啓動相機:製作圖片的意圖失敗的三星Galaxy I9000
private void saveFullImage() {
String storageState = Environment.getExternalStorageState();
if (storageState.equals(Environment.MEDIA_MOUNTED)) {
String path = Environment.getExternalStorageDirectory().getName()
+ File.separatorChar + "Android/data/"
+ RegistrationDetails.this.getPackageName() + "/files/"
+ md5("filedummy") + ".jpg";
File photoFile = new File(path);
try {
if (photoFile.exists() == false) {
photoFile.getParentFile().mkdirs();
photoFile.createNewFile();
}
} catch (IOException e) {
Log.e(TAG, "Could not create file.", e);
}
Log.i(TAG, path);
Uri fileUri = Uri.fromFile(photoFile);
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);
startActivityForResult(intent, TAKE_PICTURE);
} else {
new AlertDialog.Builder(this)
.setMessage(
"External Storeage (SD Card) is required.\n\nCurrent state: "
+ storageState).setCancelable(true)
.create().show();
}
}
而且我在onActivityResult下列代碼顯示,圖像拍攝完畢,所以我可以進行下一步:
} else if (requestCode == TAKE_PICTURE) {
if (data == null) {
Toast toast = Toast.makeText(getApplicationContext(),
"Take Picture finished", 10);
toast.show();
}
而且我已經定義在AndroidManifest以下設置:android.permission.CAMERA和android.permission.WRITE_EXTERNAL_STORAGE
的啓動相機意圖的作品,但是當我拍照並點擊保存時,它不會返回到onActivityResult,我的應用程序崩潰。
有人可以幫助我嗎?
謝謝
你可以告訴Repertoires_S是什麼嗎?這是一個特殊的班級嗎?如果是的話,你能否也請包括代碼?謝謝。 – Tand
這只是一個自定義函數,它給了我一個保存圖片的目錄。你可以用你想要的任何路徑代替這個函數(比如sdcard路徑) –