Taking a picture and saving it into gallery in a separate folder

时间:2016-04-04 16:34:42

标签: java android android-studio

I have made an application where the user can take a photo and save it into their gallery in a separate folder named "SOC". This works on one of my Android devices however on the other device the user can take the picture but the image doesn't save for some reason. The device the image saves on is Android 4.2 the device it does not save the image on is Android 5.0 not sure if this has anything to do with it. My Code is as fallows

static final int REQUEST_IMAGE_CAPTURE = 1;
private static final int CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE = 0;
public void onClickbtnCamera(View v)
{
    Intent imageIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
    String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
    Uri uriSavedImage = Uri.fromFile(new File("/storage/emulated/0/DCIM/SOC","QR_"+timeStamp+ ".png"));
    imageIntent.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage);
    startActivityForResult(imageIntent, 1);

}
   @Override
    protected void onActivityResult(int requestCode,
                                    int resultCode, Intent data) {
    if (requestCode == 1) {

        //Check for succesful result code
        if (resultCode == -1) {
            //Show your Toast when the result is a success.
            Toast toast = Toast.makeText(getApplicationContext(),
                    "Picture is saved in your SOC gallery", Toast.LENGTH_SHORT);
            toast.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, 100, 0);
            toast.show();
        }

    }
}

0 个答案:

没有答案