android相机takePicture出错了

时间:2013-12-03 08:06:55

标签: java android android-intent

logcat消息提醒:

failure delivering result ResultInfo{who = null,request=131073,result=-1,date=null}

fatal exception at com.example.newpingziyi.FindFragment.doPhoto(FindFragment.java:178);

178lines:

Cursor cursor = getActivity().managedQuery(photoUri, pojo, null, null,
            null);
照片拿起后

onActivityResult

public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == Activity.RESULT_OK) {
        doPhoto(requestCode, data);
    }
    super.onActivityResult(requestCode, resultCode, data);
}

private void doPhoto(int requestCode, Intent data) {
    if (requestCode == SELECT_PIC_BY_PICK_PHOTO) {
        if (data == null) {
            Toast.makeText(getActivity(), R.string.photo_err,
                    Toast.LENGTH_LONG).show();
            return;
        }
        photoUri = data.getData();
        if (photoUri == null) {
            Toast.makeText(getActivity(), R.string.photo_err,
                    Toast.LENGTH_LONG).show();
            return;
        }
    }
    String[] pojo = { MediaColumns.DATA };

    // fatal exception
    Cursor cursor = getActivity().managedQuery(photoUri, pojo, null, null,
            null);

    if (cursor != null) {

        int columnIndex = cursor.getColumnIndexOrThrow(MediaColumns.DATA);
        cursor.moveToFirst();
        picPath = cursor.getString(columnIndex);
        try {
            if (Integer.parseInt(Build.VERSION.SDK) < 14) {
                cursor.close();
            }
        } catch (Exception e) {
            Log.e(TAG, "error:" + e);
        }
    }
    Log.i(TAG, "imagePath = " + picPath);
    if (picPath != null) {

        Intent startEx = new Intent(getActivity(), PhotoPre.class);
        startEx.putExtra(SAVED_IMAGE_DIR_PATH, picPath);
        startActivity(startEx);

    } else {
        Toast.makeText(getActivity(), R.string.photo_err, Toast.LENGTH_LONG)
                .show();

    }

}

1 个答案:

答案 0 :(得分:0)

使用此

cursor.moveToLast();

而不是cursor.moveToFirst();