我使用选项卡活动作为主要活动,其中有 4 个选项卡。一个选项卡是具有三个按钮的活动组。每个按钮都是一个活动。我在其中一项活动中使用相机。我知道它的工作原理,因为我已在存储卡中签入图像已保存,但它没有调用 Onactivityresult() 方法。
这是为了显示 ContentView
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
View viewToLoad = LayoutInflater.from(this.getParent()).inflate(R.layout.enter_expenses, null);
this.setContentView(viewToLoad);
此代码用于拍摄图像
dbimgguid = UUID.randomUUID();
imagename =dbimgguid.toString();
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
photo = new File(Environment.getExternalStorageDirectory(), "Expenses"+imagename+".jpg");
intent.putExtra(MediaStore.EXTRA_OUTPUT,Uri.fromFile(photo));
imageurl = Uri.fromFile(photo);
startActivityForResult(intent, CAMERA_RECEIPTREQUEST);
这是活动结果
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
System.out.println(requestCode);
System.out.println(resultCode);
switch(requestCode)
{
case CAMERA_RECEIPTREQUEST:
if(resultCode== Activity.RESULT_OK)
{
//Toast.makeText(this, "Receipt Image Saved", Toast.LENGTH_SHORT).show();
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 8;
//ImageView jpgView = (ImageView)findViewById(R.id.imageView1);
Bitmap receipt = BitmapFactory.decodeFile(photo.toString(),options);
String image = "Expenses"+imagename+".jpg";
Intent imagepass = new Intent(ExpensesActivity.this,ReviewReceiptImage.class);
imagepass.putExtra("receipt", receipt);
imagepass.putExtra("imagename", image);
startActivityForResult(imagepass, CAMERA_CONFIRMRECEIPT);
Toast.makeText(this, "Receipt Image Saved", Toast.LENGTH_SHORT).show();
}
case CAMERA_CONFIRMRECEIPT:
Toast.makeText(this, "Receipt Image Saved", Toast.LENGTH_SHORT).show();
if(resultCode == CAMERA_CONFIRMRECEIPT)
{
take_receipt.setEnabled(false);
take_receipt.setVisibility(View.GONE);
show_receipt.setEnabled(true);
show_receipt.setVisibility(View.VISIBLE);
}
break;
}
}
谢谢你们的帮助