store an image in internal storage in android

前端 未结 2 488
说谎
说谎 2021-01-03 14:20

I am working now on application that start the camera and take a photo, I didn\'t use camera activity, but I wrote my camera app and I want to save the taken image in the in

2条回答
  •  情书的邮戳
    2021-01-03 15:10

    Why don't you use the camera activity and save images to internal storage by creating temp folder that has writable permission which allow other application to write to this folder and take the image to its path and then after the camera activity return you can move the image to another internal storage folder but with private permission as follow

    
    
    //the temp folder to start the camera activity with
    String path = getDir("images", Context.MODE_WORLD_WRITEABLE).getPath() + "/test.jpg";
    
    //start the camera activity
    File file = new File(path);
    Uri outputFileUri = Uri.fromFile(file);
    
    Intent intent = new Intent(
    android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
    intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
    startActivityForResult(intent, CAMERA_ACTIVITY);
    

    and in onActivityResult method move it to folder with private permission it will work fine as I tested it

提交回复
热议问题