2013-03-29 2 views
0
protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
     switch (requestCode) 
     { 
     case TAKE_IMAGE: 
      try { 
       if (resultCode == RESULT_OK) { 
        // we need to update the gallery by starting MediaSanner service. 
        mScanner = new MediaScannerConnection(ProfilePicFromCamera.this,new MediaScannerConnection.MediaScannerConnectionClient() 
        { 
         public void onMediaScannerConnected() { 
          mScanner.scanFile(imageUri.getPath(),null /*mimeType*/); 
        }   
          public void onScanCompleted(String path, Uri uri) { 
          if (path.equals(imageUri.getPath())) { 
           mScanner.disconnect(); 
           ProfilePicFromCamera.this.runOnUiThread(new Runnable() { 
             public void run() { 
              updateUI(); 
            } 
           }); 
          } 
         } 
        }); 
        mScanner.connect(); 

       } 
      } catch (Exception e) { 
       e.printStackTrace(); 
      } 
      break; 
     case UPLOAD_IMAGES: 
      if(resultCode==RESULT_OK) 
       {  
         if(file.exists()) 
         file.deleteOnExit(); 
       } 
      break;  } 
    } 

ответ

2
public void onActivityResult(int requestCode, int resultCode, Intent data) { 
    // TODO Auto-generated method stub 
    super.onActivityResult(requestCode, resultCode, data); 

      if (requestCode == CAMERA_REQUEST && resultCode == getActivity().RESULT_OK)  { 
        File file = new File(mCapturedImagePath); 
        file.delet(); 
      } 
    } 

or u can use only this(as your condition) 
File file = new File(mCapturedImagePath); 
file.delet(); 
0
File file = new File(Environment.getExternalStorageDirectory()+"image_name"); //if your image is directly inside sdcard 
file.delete(); 
0

использование ниже кода может помочь вам.

File fdelete = new File(file_dj_path); 
    if (fdelete.exists()) { 
     if (fdelete.delete()) { 
      System.out.println("file Deleted :" + file_dj_path); 
     } else { 
      System.out.println("file not Deleted :" + file_dj_path); 
     } 
    } 

ниже код для обновления галереи после удаления изображения

sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, 
Uri.parse("file://" + Environment.getExternalStorageDirectory()))); 

проверить это: https://stackoverflow.com/a/10716773/1381827

+0

Это только удаление изображения из image_folder, не удаляя изображение из DCIM/Camera. пожалуйста, помогите мне, как удалить изображение из папки DCIM/Camera, а также из галереи. – Ash

Смежные вопросы