android-external-storage

Unable to write files in Android P

谁说胖子不能爱 提交于 2019-12-01 22:26:10
I couldn’t write files in Android P Memory Card. The same code is working fine in Android O. new File(file.getParent()).mkdirs(); output = new ObjectOutputStream(new FileOutputStream(file)); output.writeObject(obj); I am able to read the files from the same device(Memory Card), but when I try to write the file, it is throwing Permission Denied exception. Initially it was throwing me No such file or Directory , but after giving root permissions, it is throwing Permission Deniod exception. Note: My app is system privileged app and also I have given the Devicewith root permission by adb root,

Permission Denial: requires android.permission.READ_EXTERNAL_STORAGE, or grantUriPermission() (API 23)

安稳与你 提交于 2019-12-01 08:51:37
I am trying to request user permissions at runtime. The API is 23 and I want to pick up an image from the phone's gallery. Following some snippets, this is the code I have so far: In the onCreate() of the Activity I check: if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) { imageUploader5.setEnabled(true); ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.CAMERA, Manifest.permission.WRITE_EXTERNAL_STORAGE }, 0); } Then I override: @Override public void onRequestPermissionsResult(int requestCode, String[]

Permission Denial: requires android.permission.READ_EXTERNAL_STORAGE, or grantUriPermission() (API 23)

可紊 提交于 2019-12-01 06:40:45
问题 I am trying to request user permissions at runtime. The API is 23 and I want to pick up an image from the phone's gallery. Following some snippets, this is the code I have so far: In the onCreate() of the Activity I check: if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) { imageUploader5.setEnabled(true); ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.CAMERA, Manifest.permission.WRITE_EXTERNAL_STORAGE },

How to check availability of space on external storage?

独自空忆成欢 提交于 2019-12-01 02:34:41
How do you check if the SD card is full or not so that your application can decide if it can continue to do its job i.e. write to external storage or notify the user that storage has run out of space. Jonik Watch out with StatFs & int overflow on newer devices The approach in this answer is broken on devices with large external storage . For example on my Nexus 7, it currently returns ~2 GB when in reality there is ~10 GB of space left. // DOES NOT WORK CORRECTLY ON DEVICES WITH LARGE STORAGE DUE TO INT OVERFLOW File externalStorageDir = Environment.getExternalStorageDirectory(); StatFs statFs

android get all external storage path for all devices

落花浮王杯 提交于 2019-12-01 01:23:15
getExternalStorageDirectory() return SD card path on my phone. ( Huawei Y320 - android 4.2.2 ). now, how to get path Phone Storage path for all devices and all API? loot at bottom screenshot. I'm using this method: public static final String SD_CARD = "sdCard"; public static final String EXTERNAL_SD_CARD = "externalSdCard"; private static final String ENV_SECONDARY_STORAGE = "SECONDARY_STORAGE"; public static Map<String, File> getAllStorageLocations() { Map<String, File> storageLocations = new HashMap<>(10); File sdCard = Environment.getExternalStorageDirectory(); storageLocations.put(SD_CARD,

How to check availability of space on external storage?

≡放荡痞女 提交于 2019-11-30 22:15:26
问题 How do you check if the SD card is full or not so that your application can decide if it can continue to do its job i.e. write to external storage or notify the user that storage has run out of space. 回答1: Watch out with StatFs & int overflow on newer devices The approach in this answer is broken on devices with large external storage . For example on my Nexus 7, it currently returns ~2 GB when in reality there is ~10 GB of space left. // DOES NOT WORK CORRECTLY ON DEVICES WITH LARGE STORAGE

Copy file from the internal to the external storage in Android

喜你入骨 提交于 2019-11-30 20:59:30
My app ( Android API 15 ) makes a picture and stores it in the internal memory's folder. Now, I want to copy this file to another folder inside of the external storage, e.g. /sdcard/myapp . I tried the following approaches: Approach #1: private void copyFile(File src, File dst) throws IOException { File from = new File(src.getPath()); File to = new File(dst.getPath()); from.renameTo(to); } Approach #2: private void copyFile(File src, File dst) throws IOException { FileChannel inChannel = null; FileChannel outChannel = null; try { inChannel = new FileInputStream(src).getChannel(); outChannel =

FileProvider and secondary external storage

半城伤御伤魂 提交于 2019-11-30 14:15:49
How can I serve files from the SECONDARY external storage using the FileProvider ? The current implementation of the FileProvider handles only the first directory returned by ContextCompat.getExternalFilesDirs ... } else if (TAG_EXTERNAL_FILES.equals(tag)) { File[] externalFilesDirs = ContextCompat.getExternalFilesDirs(context, null); if (externalFilesDirs.length > 0) { target = externalFilesDirs[0]; } } ... It seems, that there is no way to define a <path> entry for the FileProvider , that matches the secondary external storage path... And the answer is... FileProvider does not support that.

Android write files to USB via OTG cable

不羁的心 提交于 2019-11-30 07:41:05
问题 I've been searching for many topics about android file writing, yet most of them wanted to write files to android internal storage. Others who wanted to write files on external SD card didn't success at all. My case is quite similar but I think that writing files to external USB is a totally different case. I am using Samsung galaxy Note II running stock TouchWiz 4.4.2 [not rooted]. My phone supports micro-USB-OTG and I can mount my USB as rwxrwx--x without rooting. The complete path of my

FileProvider and secondary external storage

落爺英雄遲暮 提交于 2019-11-29 19:28:13
问题 How can I serve files from the SECONDARY external storage using the FileProvider ? The current implementation of the FileProvider handles only the first directory returned by ContextCompat.getExternalFilesDirs ... } else if (TAG_EXTERNAL_FILES.equals(tag)) { File[] externalFilesDirs = ContextCompat.getExternalFilesDirs(context, null); if (externalFilesDirs.length > 0) { target = externalFilesDirs[0]; } } ... It seems, that there is no way to define a <path> entry for the FileProvider , that