0

I want to store google map screenshots on my sd card co a wrote this code but I don't know if I misunderstood the term external storage or am I doing something wrong because everything works fine but screenshots are saved in my internal phone memory instead of sd card

 public void snapshot(View view) {
    boolean mExternalStorageAvailable = false;
    boolean mExternalStorageWriteable = false;
    String state = Environment.getExternalStorageState();

    if (Environment.MEDIA_MOUNTED.equals(state)) {
        mExternalStorageAvailable = mExternalStorageWriteable = true;
    } else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
        mExternalStorageAvailable = true;
        mExternalStorageWriteable = false;
    } else {
        mExternalStorageAvailable = mExternalStorageWriteable = false;
    }

    if(mExternalStorageWriteable){
        File sdCard = Environment.getExternalStorageDirectory();
        File dir = new File (sdCard.getAbsolutePath() + "/DCIM/100MEDIA/");
        dir.mkdirs();
        String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
        final File file = new File(dir, "MapScreen"+timeStamp+".png");

        GoogleMap.SnapshotReadyCallback callback = new GoogleMap.SnapshotReadyCallback() {
            Bitmap bitmap;

            @Override
            public void onSnapshotReady(Bitmap snapshot) {
                bitmap = snapshot;
                try {
                    FileOutputStream out = new FileOutputStream(file);
                    bitmap.compress(Bitmap.CompressFormat.PNG, 90, out);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        };
        mMap.snapshot(callback);
    }
}

I'm using Htc One M8s

Lowrider
  • 31
  • 1
  • 5
  • Take a look at https://developer.android.com/guide/topics/data/data-storage.html#filesExternal – antonio Jun 15 '16 at 16:02
  • Check out the answer from this question: http://stackoverflow.com/questions/17674634/saving-and-reading-bitmaps-images-from-internal-memory-in-android – user3673952 Jun 15 '16 at 16:21
  • Possible duplicate of [How can I get external SD card path for Android 4.0+?](http://stackoverflow.com/questions/11281010/how-can-i-get-external-sd-card-path-for-android-4-0) – Bryan Jun 15 '16 at 16:53
  • Thanks but these didn't help. I can't get path to my sdcard I think somehow it's wirtualy mounted and can't get access, evan if I get path /sdcard from System.getenv("EXTERNAL_STORAGE") it saves the image to internal phone memory and not the actual sdcard. – Lowrider Jun 16 '16 at 22:03

1 Answers1

0

External storage is any storage that world-readable, not necessarily an SD card (or other removable device). While internal storage is storage that is, by default, private to the application.

To specify removable external storage is much more complicated because many device manufactures use different directory structures. Try the answer here.

Community
  • 1
  • 1
Bryan
  • 14,756
  • 10
  • 70
  • 125
  • Thanks but unfortunately it did't work for me. I don't know why but System.getenv("EXTERNAL_STORAGE") retrives the path /sdcard but when I save to this path the files always get saved to the phone memory and not the actual sdcard when I som file manager appp it showed there math /storage for the sd card but even if I enered this path the app woudlnt save on sd card(in this case it didn't save anywhere) – Lowrider Jun 16 '16 at 22:00