-->

android camera and gallery not working in nexus 5

2020-06-27 09:59发布

问题:

In my application I use camera and gallery to upload the selected image to server. it's working fine till 4.4.2, but in 4.4.4 nexus5 both camera and gallery don't work. my camera part is in a Fragment.If I try to take a photo using the camera or pick a photo using the gallery I get "please retry" message as per my code.

camera action code:

        String path = Environment.getExternalStorageDirectory()
                + "/appname";
        File photopath = new File(path);
        if (!photopath.exists()) {
            photopath.mkdir();
        }

        try {
            Intent captureIntent = new Intent(
                    MediaStore.ACTION_IMAGE_CAPTURE);

            startActivityForResult(captureIntent, CAMERA_CAPTURE);
        } catch (ActivityNotFoundException anfe) {
            String errorMessage = "Whoops - your device doesn't support capturing images!";
            Toast toast = Toast.makeText(getActivity(), errorMessage,Toast.LENGTH_SHORT);
            toast.show();
        }

......

public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    try {
        Log.e("request code", "" + requestCode);
        Log.e("result code", "" + resultCode);
        Log.e("Activity.RESULT_OK", "" + getActivity().RESULT_OK);
    }
    catch(Exception e) {
        Toast.makeText(getActivity(), "Please retry", Toast.LENGTH_SHORT).show();
    }
}

what is the problem behind the 4.4.4 version? or is it my mistake? How can I solve the problem?