嗨我想在下一個activity中捕獲圖像並對該圖像進行一些操作。我嘗試在Samsung和Moto G中運行下面的代碼並且它的工作正常。我用redmi note3嘗試了相同的代碼,點擊右邊標記它來到相同的活動。如何解決這個問題?這是我的代碼:resultCode == RESULT_OK在redmi中不起作用note3
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
try{
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
Uri outputFileUri = Uri.fromFile(originalFile);
intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
} catch (ActivityNotFoundException e) {
Toast.makeText(getApplicationContext(), "No camera app found!", Toast.LENGTH_LONG).show();
}
}
});
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode,resultCode,data);
if (requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE) {
Bitmap imageData = null;
if (resultCode ==Activity.RESULT_OK) {
try
{
BitmapFactory.Options bitopt=new BitmapFactory.Options();
imageData = BitmapFactory.decodeFile(imagePath, bitopt);
Uri tempUri = getImageUri(getApplicationContext(), imageData);
Intent i = new Intent(this, Image_R.class);
i.putExtra("imageUri", tempUri.toString());
startActivityForResult(i, 3);
}
catch (Exception e) {
Toast.makeText(this, "Unable to save image", Toast.LENGTH_LONG).show();
}
} else if (resultCode == RESULT_CANCELED) {
// User cancelled the image capture
}
}
調試onActivityResult方法和檢查什麼是錯誤的,在該步驟然後發佈它更好地幫助 – Vickyexpert
@Vickyexpert當我運行這段代碼發送resultCode == Activity.RESULT_OK越來越resultCode爲= 0爲redmi和moto resultCode = -1。之後,它不會嘗試在紅米移動塊。 – Amshu
此代碼在片段或活動? –