我有一个启动相机意图的按钮,然后将照片发送到另一个活动。我使用onActivityResult事件来接收照片,然后启动另一个应该以完整尺寸显示该照片的意图。然而,尽管没有错误,但其他意图从未开始。以下是相关代码:
private void openBackCamera() {
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
String imageFileName = timeStamp + ".jpg";
File storageDir = Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES);
pictureImagePath = storageDir.getAbsolutePath() + "/" + imageFileName;
File file = new File(pictureImagePath);
outputFileUri = Uri.fromFile(file);
SharedPreferences.Editor editor;
editor = getSharedPreferences("My Prefs", MODE_PRIVATE).edit();
editor.putString("imagepath", pictureImagePath); //add item Color with the selected color code
editor.commit();
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
startActivityForResult(cameraIntent, 1);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 1 && resultCode == RESULT_OK) {
preferences = getSharedPreferences("My Prefs", MODE_PRIVATE);
String imagepath = preferences.getString("imagepath", "");
File file = new File(imagepath);
outputFileUri = Uri.fromFile(file);
myBitmap = BitmapFactory.decodeFile(imagepath);
Intent i = new Intent(CameraExampleActivity.this, Betengan.class);
i.putExtra("photo", myBitmap);
CameraExampleActivity.this.startActivity(i);
}
else if (resultCode == RESULT_CANCELED) {
Toast.makeText(this, "Capture Cancelled", Toast.LENGTH_LONG)
.show();
} else {
Toast.makeText(this, "Capture failed", Toast.LENGTH_LONG)
.show();
}
super.onActivityResult(requestCode, resultCode, data);
}