0

I have made an app with gridviews and a lot of pictures.

I have a fullscreenactivity and everytime I'm opening a picture in fullscreen it's saved in the camera folder but how can I delete it after fullscreen?

   @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.full_image);

        // get intent data
        Intent i = getIntent();

        // Selected image id
        int position = i.getExtras().getInt("id");
        ImageAdapter imageAdapter = new ImageAdapter(this);

        ImageView imageView = (ImageView) findViewById(R.id.full_image_view);
        imageView.setImageResource(imageAdapter.mThumbIds[position]);
        BitmapDrawable bm = (BitmapDrawable) imageView.getDrawable();
        Bitmap mysharebmp = bm.getBitmap();
        String path = Images.Media.insertImage(getContentResolver(),
                            mysharebmp, "MyImage", null);
        Uri uri = Uri.parse(path);
        Intent sharingIntent = new Intent(Intent.ACTION_SEND);
        sharingIntent.setType("image/*");
        sharingIntent.putExtra(Intent.EXTRA_STREAM, uri);
        startActivity(Intent.createChooser(sharingIntent,
                            "Share image using"));

    }
}

I hope that are all informations you need.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129

1 Answers1

0

in your full screen activity when ever come in increate() method then u will found one file path just delete that path from there from this code

    File file = new File(selectedFilePath);
boolean deleted = file.delete();

After delete just refresh media gallery class like this using from this line i.e u can see the changes after delete of that picture.

sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(new File(filePath))));

also take permission

 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
Bhanu Sharma
  • 5,135
  • 2
  • 24
  • 49
  • public static final String ACTION_MEDIA_SCANNER_SCAN_FILE Added in API level 1 – Bhanu Sharma Apr 03 '14 at 07:52
  • Thank you for your help but i think i´m doing it wrong it crashes with 04-03 09:59:02.842: W/ContentResolver(7682): Failed to get type for: content://media/external/images/media/22272/storage/sdcard0 (Unknown URL : content://media/external/images/media/22272/storage/sdcard0) –  Apr 03 '14 at 08:00
  • i put it sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse(path + Environment.getExternalStorageDirectory()))); sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(new File(path)))); after the startActivity...? –  Apr 03 '14 at 08:01
  • just try to run only delete method not refresh and let me know what u found – Bhanu Sharma Apr 03 '14 at 08:03
  • It´s still the same only with sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse(path + Environment.getExternalStorageDirectory()))); –  Apr 03 '14 at 08:14
  • One wierd error is 04-03 10:12:55.747: E/AndroidRuntime(8494): Caused by: java.lang.SecurityException: Permission Denial: not allowed to send broadcast android.intent.action.MEDIA_MOUNTED from pid=8494, uid=10229 because i set permission in manifest –  Apr 03 '14 at 08:15
  • now see my edited ans and try to delete with this code dude and also refresh it – Bhanu Sharma Apr 03 '14 at 08:35
  • made it working with that code: getContentResolver().delete(uri, null, null); sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(new File(path)))); But now i can´t share the pictures because it´s going deleted before the share how can i make it that it´s deleted after the share? –  Apr 03 '14 at 08:35
  • made that but it´s not working. it´s deleting the pic before the share action? if i put it after share and } it´s not working too if you add getContent... to your answer i will accept it as right :) maybe you can help me with the new problem? or should i open a new question? thx dude for ur help! –  Apr 03 '14 at 08:42
  • just use async task for sharing dude and in on post u jusr delete that file simple as that dude :) – Bhanu Sharma Apr 03 '14 at 08:43
  • what do i have to put in selectedfilepath? –  Apr 03 '14 at 08:44
  • ohk just pass your file path which u want to be delete – Bhanu Sharma Apr 03 '14 at 08:45
  • dude a lot to learn i have ^^ i don´t know what u mean that i use async for sharing i´m using async for class BitmapWorkerTask extends AsyncTask.... but your answer is mindblowing for me don´t have enough skill to understand it. –  Apr 03 '14 at 08:47
  • if i use my path (path) then i have The value of the local variable deleted is not used? –  Apr 03 '14 at 08:48
  • just pass the file path dude image file path which u want to delete – Bhanu Sharma Apr 03 '14 at 08:49
  • passed the path storage/sdcard0/DCIM/Camera still the same The value of the local variable deleted is not used :( –  Apr 03 '14 at 09:02
  • make it global variable dude – Bhanu Sharma Apr 03 '14 at 09:14
  • dude i really thank you for your help but for my skills that´s to much but 2 last questions i´m thinking about How could i save the pics in my own folder instead of the camera folder? And is there no way to start getContentResolver().delete(uri, null, null); sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(new File(path)))); after exit fullscreen? because that code is working... Thank you really for ur time dude!!!!!! –  Apr 03 '14 at 09:34
  • i´m opening a new question is the best solution i think :D but i mark your answer as right i´m sure it´s working... –  Apr 03 '14 at 09:51