我有两个问题:
第一:我想知道当我使用方法 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);
}
谢谢