It even can't make a folder on the sdcard. When the camera takes the photo, it doesn't respond when I press the 'OK' Button. What's wrong with my code?
public static final String MACCHA_PATH = Environment.getExternalStorageDirectory().getPath() + "/Twigit";
public static final String PHOTO_PATH = MACCHA_PATH + "/camera.jpg";
public static boolean takePhoto(Activity activity) {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File fileDir = new File(MACCHA_PATH);
boolean isSuccessful = true;
if (!fileDir.exists()) {
isSuccessful = fileDir.mkdir();
}
if(!isSuccessful) {
return false;
} else {
File file = new File(PHOTO_PATH);
Uri outputFileUri = Uri.fromFile(file);
intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
activity.startActivityForResult(intent, TAKEPHOTO);
return true;
}
}
Run Code Online (Sandbox Code Playgroud)
你有这个吗?您需要重写 onActivityResult。当您使用 startActivityForResult 时,它将在 onResume 之前调用。requestCode 将是您用于开始拍照活动的代码。在你的情况下,它将是 TAKEPHOTO..
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == TAKEPHOTO) {
if (resultCode == RESULT_OK) {
//Pic taken
} else {
//Pic not taken
}
}
}
Run Code Online (Sandbox Code Playgroud)
编辑:看看这个链接 http://achorniy.wordpress.com/2010/04/26/howto-launch-android-camera-using-intents/
| 归档时间: |
|
| 查看次数: |
1661 次 |
| 最近记录: |