android-external-storage

Does Environment.getExternalStorageDirectory() returns a usable data folder when no sd card is mounted?

廉价感情. 提交于 2019-12-04 02:38:44
Imagine an Android device with no sd memory insterted. Only its own internal memory. I'm not sure what Environment.getExternalStorageDirectory() returns in this case. Null or a internal memory location valid for permanent data storage? Raghunandan public static File getExternalStorageDirectory() Added in API level 1 Gets the Android external storage directory. This directory may not currently be accessible if it has been mounted by the user on their computer, has been removed from the device, or some other problem has happened. You can determine its current state with getExternalStorageState()

differences between /sdcard/emulated/0 and /sdcard

人盡茶涼 提交于 2019-12-04 00:15:44
I'm goig to be mad with a strange issue. If i create a folder inside my code as directory_path = Environment.getExternalStorageDirectory() + "/" + context.getResources().getString(R.string.app_name); directory = new File(directory_path); if (!directory.exists()) { directory.mkdirs(); } a new folder is created inside /sdcard/ . If i try to print on logcat directory_path variable, the path is different: /storage/emulated/0/ and if i go to that path, i found another folder with the same name of the one created on /sdcard/ . This is a problem for me because when i try to write some data into that

getExternalCacheDir() returns null after clearing data

蹲街弑〆低调 提交于 2019-12-03 15:11:35
问题 I have a simple app that access and writes data to external storage. Everything works fine until I go to Settings -> Apps -> App Info and clear data via "Clear data" button, then every call to getExternalCacheDir() starts returning null. I have been developing on Nexus 7 running Android 4.2.2. My manifest looks like: <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.package" android:versionCode="5" android:versionName="1.3" xmlns:tools="http://schemas

Why don't I have permission to write to app dir on external storage?

≡放荡痞女 提交于 2019-12-03 08:40:47
问题 The TL;DR question summary: My Android app tries to write to the app's external storage directory on an SD card. It fails with a permissions error . But the same code (method), extracted into a minimal test app, succeeds! Since our target API level includes KitKat and later (as well as JellyBean), and KitKat restricts apps from writing anywhere on the SD card except the app's designated external storage directory, the app tries to write to that designated directory, /path/to/sdcard/Android

getExternalCacheDir() returns null after clearing data

戏子无情 提交于 2019-12-03 04:53:55
I have a simple app that access and writes data to external storage. Everything works fine until I go to Settings -> Apps -> App Info and clear data via "Clear data" button, then every call to getExternalCacheDir() starts returning null. I have been developing on Nexus 7 running Android 4.2.2. My manifest looks like: <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.package" android:versionCode="5" android:versionName="1.3" xmlns:tools="http://schemas.android.com/tools"> <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17" /> <uses

Force access to external removable microSD card

匆匆过客 提交于 2019-12-03 02:35:23
I'm using a Samsung A3, Android 5.0.2. I'm using this setup to compile apps, i.e. Android 4.1 Jelly Bean (API 16) target. I precisely know the path of the external removable microSD card, it is /mnt/extSdCard/ (see also Note #7 below). Problem: I notice that File myDir = new File("/mnt/extSdCard/test"); myDir.mkdirs(); doesn't work: no directory is created. Also: File file = new File("/mnt/extSdCard/books/test.txt"); // the folder "books" already exists on the external microSD card, has been created from computer with USB connection FileOutputStream fos = new FileOutputStream(file); produces

Opening pdf with other app from assets folder, workarounds

我的未来我决定 提交于 2019-12-02 19:30:50
问题 In my app, I've got some pdf's stored in my assets folder. I've seen libraries for opening pdf-pages, but I think that apps such as quickoffice are better at showing the pdf's than the libraries I've seen. Therefore, i wish to show the pdf using Intent.ACTION_VIEW , like this: Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(fileUri, "application/pdf"); getActivity().startActivity(intent); However, this is not possible because third party apps are not allowed to acces

Opening pdf with other app from assets folder, workarounds

☆樱花仙子☆ 提交于 2019-12-02 07:43:44
In my app, I've got some pdf's stored in my assets folder. I've seen libraries for opening pdf-pages, but I think that apps such as quickoffice are better at showing the pdf's than the libraries I've seen. Therefore, i wish to show the pdf using Intent.ACTION_VIEW , like this: Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(fileUri, "application/pdf"); getActivity().startActivity(intent); However, this is not possible because third party apps are not allowed to acces files in my package. Therefore I need to copy the files to the external storage and provide that file to

Issues traversing through directory hierarchy with Android Storage Access Framework / DocumentProvider using MTP

流过昼夜 提交于 2019-12-02 05:29:54
UPDATE: My initial question may be misleading so I want to rephrase it: I want to traverse through the hierarchy tree from an MTP connected device through Android's Storage Access Framework. I can't seem to achieve this because I get a SecurityException stating that a subnode is not a descendant of its parent node. Is there a way to workaround this issue? Or is this a known issue? Thanks. I'm writing an Android application that attempts to traverse and access documents through the hierarchy tree using Android's Storage Access Framework (SAF) via the MtpDocumentsProvider . I am more or less

Unable to write files in Android P

不羁岁月 提交于 2019-12-02 02:26:25
问题 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