I look into some threads to find out how to save photo into SD card. All of them said use "Environment.getExternalStorageDirectory()" to get SD card path. I have tried it, but I got "/storage/emulated/0/" which is not SD card by phone. Can anyone help me?
My device is Samsung Galaxy J7 and A5.
My another part of code using DowloadManager to save photo from url. I want to know also how to set up it to save into SD card.
DownloadManager mgr = (DownloadManager) mPhotosViewActivity.getSystemService(Context.DOWNLOAD_SERVICE);
String uRl = imageUrl;
Uri downloadUri = Uri.parse(uRl);
DownloadManager.Request request = new DownloadManager.Request(
downloadUri);
request.setAllowedNetworkTypes(
DownloadManager.Request.NETWORK_WIFI
| DownloadManager.Request.NETWORK_MOBILE)
.setAllowedOverRoaming(false).setTitle("MyFolder")
.setDescription("Photo downloaded.")
.setDestinationInExternalPublicDir("/MyFolder", "test2.jpg");
Finally I found that I am using Lollipop and I have to use "Storage Access Framework" as this link