我想捕获图像并将其保存到 SD 卡。现在它工作正常。我的问题是 1)在捕获 OK and Cancel
按钮可用后。当我单击确定时,只需将图像保存到 SD 卡中。
2)它没有onActivityResult
方法。我onActivityResult
在ActivityGroup
课堂上写了我的。
此代码用于当用户单击相机按钮时,它将打开相机并保存
//Camera
Button btnCamera =(Button)findViewById(R.id.btnCamera);
btnCamera.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
selectedImagePath = Environment.getExternalStorageDirectory()+"/"+retailerCode+"-"+count+".jpg";
imgName =retailerCode+"-"+count+".jpg";
count++;
File file = new File(selectedImagePath);
Uri outputFileUri = Uri.fromFile(file);
Intent intent = new Intent (android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
Bundle b = new Bundle();
b.putString("Activity", "RetailerOrderSActivity");
b.putString("RetailerName", seletctedRetailer);
b.putString("RetailerCode", retailerCode);
intent.putExtras(b);
intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
startActivityForResult(intent, CAMERA_PIC_REQUEST);
onPhotoTaken();
}
});
protected void onPhotoTaken() {
_taken = true;
DBAdapter dbAdapter = DBAdapter.getDBAdapterInstance(CameraMainActivity.this);
dbAdapter.openDataBase();
boolean status = dbAdapter.saveImageInfo(retailerCode,strExecutive,strBusinessUnit,strTerritoryCode,imgName,visitNumber);
if(status) {
Toast.makeText(SalesActivityGroup.group.getApplicationContext(), "Image has been saved successfully" , Toast.LENGTH_SHORT).show();
}else {
Toast.makeText(SalesActivityGroup.group.getApplicationContext(), "Image has not been saved successfully" , Toast.LENGTH_SHORT).show();
}
dbAdapter.close();
lstCaptures = getAllImage(imgDateVal.getText().toString());
imageViewTable.removeAllViews();
loadTableLayout();
}
这是 ActivityGroup 的代码
public class SalesActivityGroup extends ActivityGroup {
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
System.out.println("===REQUEST=====" +requestCode);
System.out.println("==resultCode==" +resultCode); } }
实际上我需要onPhotoTaken
从onActivityResult
. 根据当前我的代码,如果用户也单击取消,它将信息保存到数据库。图片没拍到。。
这是我的应用图像:
这是捕获图像后显示的按钮:
请任何人解决这个问题..
提前致谢