gpt4 book ai didi

android - onActivityResult 不适用于 Camera -Tab ActivityGrup

转载 作者:行者123 更新时间:2023-11-30 04:14:59 25 4
gpt4 key购买 nike

我想捕捉图像并将其保存到 SD 卡中。现在它工作正常。我的问题是 1) 捕获 OK 和 Cancel 按钮后可用。当我单击 Ok 时,只需要将图像保存到 SD 卡中。

2) 它没有到达onActivityResult 方法。我已经在 ActivityGroup 类中编写了我的 onActivityResult

此代码用于当用户单击相机按钮时,它将打开相机并保存它

       //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); } }

实际上我需要从 onActivityResult 调用 onPhotoTaken。根据当前我的代码,如果用户也单击取消,它将信息保存到数据库中。未捕获图像..

这是我的应用图片:

enter image description here

这是捕获图像后显示的按钮:

enter image description here请任何人解决这个问题..

提前致谢

最佳答案

检查以下答案

假设我有一个按钮选择,当用户点击该按钮时,相机屏幕将打开。

btn_select.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {

String fileName = new StringBuilder(String.valueOf(System.currentTimeMillis())).append(
".jpg").toString();
ContentValues values = new ContentValues();
values.put(MediaStore.Images.Media.TITLE, fileName);
mCapturedImageURI = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
values);
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, mCapturedImageURI);
startActivityForResult(intent, IShipdocsMobileConstants.CAMERA_ACTION);
}
});

用户拍照并点击保存/确定按钮(取决于移动设备)后,使用以下代码获取所拍摄图像的数据。

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
if (requestCode == IShipdocsMobileConstants.CAMERA_ACTION) {
if (resultCode == RESULT_OK) {
String[] projection = { MediaStore.Images.Media.DATA };
Cursor cursor = managedQuery(mCapturedImageURI, projection, null, null, null);
int column_index_data = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
String capturedImageFilePath = cursor.getString(column_index_data);
SelectedFileInfo selectedFileObj = null;
ArrayList<SelectedFileInfo> cameraArrList = new ArrayList<SelectedFileInfo>();
File fileObj = new File(capturedImageFilePath);
String fileSize = String.valueOf(fileObj.length()); //File Size
String fileName = Utils.getFileName(capturedImageFilePath); //File Name
}else if (resultCode == RESULT_CANCELED) {
// handle the condition in which the user didn't save the image
}
} else {
// handle the condition in which the request code was not CAMERA_ACTION , maybe send the user to the home/default screen
}

}
}

关于android - onActivityResult 不适用于 Camera -Tab ActivityGrup,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10190554/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com