0
更新:
我重新啓動了設備,現在它可以工作。像魔術一樣!
未調用片段中的OnActivityResults
原題:
我已經閱讀了我的問題有許多答案,但我仍然不能得到解決我的問題:
我有1個片段開設了一個意向,用於捕捉照片和在片段中我有方法OnActivityResults和所有工作正常。
現在,我添加了第二個片段,它也調用了具有相同代碼(但不同的請求代碼)的意圖。我不確定這是否會導致問題,但現在,當我推送批准捕獲的照片的「V」時,我將回到不同的片段,並且不會調用OnActivityResults方法。
在片段:
private static final int REQUEST_TAKE_PHOTO_CODE = 11;
private static final int REQUEST_ATTACH_PHOTO_CODE = 22;
takePhotoButton = (ImageButton)rootView.findViewById(R.id.imageButtonTakePhoto);
takePhotoButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(MainActivity.deviceHasCamera){
Intent photoIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(photoIntent, REQUEST_TAKE_PHOTO_CODE);
}
else{
Toast.makeText(activity, "No camera detected", Toast.LENGTH_SHORT).show();
}
}
});
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Log.d("EB", "onActivityResult CarAccident");
switch (requestCode) {
case REQUEST_TAKE_PHOTO_CODE:
//This case is when the user decide to Approve the captured photo
if (resultCode == Activity.RESULT_OK) {
photo = (Bitmap) data.getExtras().get("data");
imageView.setImageBitmap(photo);
Log.d("EB", "BitMap = " + photo.toString());
}
break;
case REQUEST_ATTACH_PHOTO_CODE:
if (resultCode == Activity.RESULT_OK) {
Uri selectedImage = data.getData();
Log.d("EB", "Uri fata.getData() = " + data.getData().toString());
String[] filePathColumn = {MediaStore.Images.Media.DATA};
Cursor cursor = this.activity.getContentResolver().query(
selectedImage, filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String filePath = cursor.getString(columnIndex);
cursor.close();
photo = BitmapFactory.decodeFile(filePath);
//For the case that is Android 5.0 and the photo is on the server
// and not on the device
if (photo == null){
try {
photo = getBitmapFromUri(data.getData());
Log.d("EB", "photo = getBitmapFromUri(data.getData()) = " + photo.toString());
} catch (IOException e) {
e.printStackTrace();
Toast.makeText(this.activity, FAILD_TO_ATTACH_PHOTO_MESSAGE,
Toast.LENGTH_SHORT).show();
}
}
//Set the photo to the imageView
imageView.setImageBitmap(photo);
Log.d("EB", "attached image = " + ((photo != null) ? photo.toString() : "NULL"));
}
break;
}
}
我試圖在主機活動寫:
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
}
但它不工作。希望你能幫助。 在此先感謝!
將請求代碼REQUEST_ATTACH_PHOTO_CODE調用startActivityForResult的代碼包括在內。 – blizzard
我已重新啓動我的設備,現在可以使用。像魔術一樣! –
重複的問題[檢查此](http://stackoverflow.com/a/29369154/1283715) –