开发者

selected image path save last image path when image not take from camera

开发者 https://www.devze.com 2023-04-10 15:16 出处:网络
i use camera for taking image from camera and use that image for showing it another activity..the camera open and it works and takeimage but when i am not taking the image from camera means i just ope

i use camera for taking image from camera and use that image for showing it another activity..the camera open and it works and take image but when i am not taking the image from camera means i just open the camera and click on back button means without taking image i go back then its onActivityforresult() called and showing last clicked image from camera so how to avoid it means if not take the image then it should go back to its previous activity without any nulll pointer exception and path of containing image should be null so for doing this we have to delete image from gallery or sdcard after doing it task or asign some null value to path of image ..pls help me...

my code for open camera and taking image and save it external storage is below ..

          public void function(int id){

           selectedImagePath    =             Environment.getExternalStorageDirectory() + "/photo1.jpg";
                File file = new File(selectedImagePath);
                Uri outputFi开发者_JAVA百科leUri = Uri.fromFile(file);
                Intent intent = new Intent(
                        android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
                intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);                
                startActivityForResult(intent, CAMERA_PIC_REQUEST);

        }

     public void onActivityResult(int requestCode, int resultCode, Intent data) {
            try{


            if (requestCode == CAMERA_PIC_REQUEST) {
                 if(selectedImagePath!=null){
                      Log.i("onActivityResult3","onActivityResult3");

                      Intent i=new Intent(getBaseContext(),Imageprview.class);
                      startActivity(i);
                      System.out.println(selectedImagePath);
                }

                 else
                        System.out.println("selectedImagePath is null");



                }}catch (NullPointerException e) {
                    // TODO: handle exception
                }   

so how to make selectedImagePath = null if i dont take any image from camera and back to my previous actity?


i used

if (requestCode == CAMERA_PIC_REQUEST) { if (resultCode == Activity.RESULT_OK) { } }

0

精彩评论

暂无评论...
验证码 换一张
取 消