我是 android 新手,我正在尝试制作一部分代码来保存我的应用程序拍摄的图像,该应用程序使用默认的 android 相机。一旦我退出相机,我希望图像显示在不同的活动中。现在,如果我不保存它,一旦退出相机模式就会显示图像。但是如果我也尝试保存它,相机根本不会退出并且“确定”按钮没有响应。我正在尝试构建一个应用程序,它可以拍照并将其附加到电子邮件中,并将其与 GPS 位置数据一起发送。因此,开关盒的“发送消息”部分就是出于这个原因。
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.Picture:
File file = new File(Environment.getExternalStorageDirectory().getPath() + "/My Images/" + "bhe_app" + ".jpg");
Uri imageUri = Uri.fromFile(file);
i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
i.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
startActivityForResult(i, cameraData);
break;
case R.id.SendMessage: //Sending message part
EditTextToString();
EmailIntent = new Intent(android.content.Intent.ACTION_SEND);
EmailIntent.putExtra(Intent.EXTRA_EMAIL,
new String[] { "myEmail@gmail.com" });
EmailIntent.putExtra(android.content.Intent.EXTRA_TEXT,
MessageToBeReceived);
EmailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "@"+Lattitude_data +"," +Longitude_data);
// EmailIntent.setType("message/rfc822");
EmailIntent.setType("image/jpeg");
// EmailIntent.putExtra(Intent.EXTRA_STREAM, fileUri);
startActivity(Intent.createChooser(EmailIntent,
"Choose an Email client :"));
break;
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) {
Bundle extras = data.getExtras();
bmp = (Bitmap) extras.get("data");
iv.setImageBitmap(bmp);
//iv is an image view in an activity where I display the image taken.
//bmp is defined as being Bitmap.
// final static int cameraData =0
}
}