2
我有兩個問題:startActivityForResult在片段
第一:我想知道的Cuz當我使用方法1我的應用程序運行在確定2法的向度,但我改變方法2它不能運行.. 方法1(拍照簡單):
private void takePhoto() {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
Log.d(TAG, "Take photo .......");
startActivityForResult(intent, REQUEST_IMAGE_CAPTURE);
}
和方法2:
public void dispathTakepictureIntent() {
Context context = getActivity();
PackageManager packageManager = context.getPackageManager();
if (packageManager.hasSystemFeature(PackageManager.FEATURE_CAMERA) ==false)
{
Toast.makeText(getActivity()
, "This device does not have a camera.", Toast.LENGTH_SHORT).show();
return;
}
else
{
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePictureIntent.resolveActivity(getActivity().getPackageManager()) != null)
{
File photoFile = null;
try {
photoFile = createCurrentPhotoPath();
}
catch (IOException ex)
{
Toast.makeText(getActivity(), "null photo Path", Toast.LENGTH_LONG).show();
}
if (photoFile != null) {
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,
Uri.fromFile(photoFile));
startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO);
}
}
}
}
---相機片段的onActivityResult:
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == REQUEST_TAKE_PHOTO && resultCode == Activity.RESULT_OK) {
Bundle extras = data.getExtras();
Bitmap imageBitmap = (Bitmap) extras.get("data");
if (imageBitmap != null)
Img_show.setImageBitmap(imageBitmap);
else
Toast.makeText(getActivity(), "null photo bitmap", Toast.LENGTH_LONG).show();
} else
Toast.makeText(getActivity(), "Cancel !", Toast.LENGTH_LONG).show();
}
主要問題:現在我有MainFragment擴展FragmentActivity(有片段相機和地圖)。但在片段相機當我
startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO);
然後在方法onActivityResult,所述發送resultCode送花兒給人== 0儘管必須== 1; 。誰可以顯示我的問題?我的錯在哪裏?在mainFragment
注意我只要致電:
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
}
感謝
它;仍然否認。 cuz當我調試我看到caemra片段== 0 resultCode; (Toast =取消)。我認爲我的問題在startActivityForResult和onActivityResult。 –
@ AceAkatsuki..okay ...現在告訴我你的主要關注,以解決這個問題,或者你可以使用一些其他的代碼,這將運行更高效,然後 –
@AceAkatsuki ...我已經更新了我的答案,這肯定會幫助你 –