android-sdcard

mkdirs returns false for directory on sd card while the parent directory is writable

邮差的信 提交于 2019-11-29 05:34:28
When starting my android application, I need to create a directory on the sd card, for a small number of users this fails and I can't figure out the reason for it... (I've found similar problems caused by the WRITE_EXTERNAL_STORAGE permission missing, it's there and it works for almost all users so I don't think this is reason) I've simplified the previous situation to make it easier to explain, if creating a directoy fails, I run a test case where I try to make a .test directory on the sdcard: new File(Environment.getExternalStorageDirectory(), ".test").mkdir() -> false new File(Environment

How to check if a SD Card has been inserted to the tablet or not : Android?

余生长醉 提交于 2019-11-29 05:15:19
I am working on a simple app, which should be able to access files from internal storage and as well as from external storage (Removable cards) like Micro SD cards (when an user inserts a SDCARD). (Not the internal sdcard which comes with the device, I know it can be accessed using Environment.getExternalStorageDirectory() ) Is it possible to find out if an user has inserted a sdcard to the device? If yes, Is it possible to get the path of that SD CARD? I found that hard coding the path was not a good option, cos different devices has different paths for sdcard inserted by user. Any help is

Unable to write files on sdcard android

佐手、 提交于 2019-11-29 04:33:34
I have an app which saves backup files on SD-Card. It works fine on HTC Nexus One, and other android phones, but with some phones it doesn't work (reading or writing). In the manifest I have set this: <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> For example (when I set the path for recording file) : OutputStream output = new FileOutputStream(Environment.getExternalStorageDirectory() + "/mydata.dat"); //Writing file...(It doesn't work) How I can get the right path of the SD-Card for manipulating files rightly? When you say "it doesn't work".... what exactly

How to get the internal and external sdcard path in android

末鹿安然 提交于 2019-11-29 01:21:48
Most of the new android devices have an internal sdcard and an external sdcard. I want to make a file explorer app but I can't find out how to get the path to use in my app because File file = Environment.getExternalStorageDirectory(); just returns in most device /mnt/sdcard but there is another path for the other external sdcard like /storage1 or /storage2 . Any help appreciated. AnV How to get the internal and external sdcard path in android Methods to store in Internal Storage: File getDir (String name, int mode) File getFilesDir () Above methods are present in Context class Methods to

Do I have to declare both WRITE_EXTERNAL_STORAGE and READ_EXTERNAL_STORAGE?

假装没事ソ 提交于 2019-11-29 01:01:53
Is it enough to declare <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> or do I also have to declare <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> ? The Javadocs omit this important information. READ_EXTERNAL_STORAGE only exists as of Jelly Bean (Level 16). According to the docs , all applications as of Jelly Bean have that permission, even without declaring it: Provides protected read access to external storage. In Android 4.1 by default all applications still have read access. This will be changed in a future release to require that

How to get all image files available in sdcard in android? [duplicate]

大憨熊 提交于 2019-11-29 00:47:15
Possible Duplicate: How to get all the pictures from the sdcard of emulator and display it in a listView? I have so many folders under sdcard. Each folder contains image files, text files and sub folders. How do i get all image files available in all folders & subfolders under sdcard? I need to store all image file paths into one array. Can anyone help me please. You can use below code to search all image from SD Card . private String SD_CARD_ROOT; File mFile=Environment.getExternalStorageDirectory(); SD_CARD_ROOT=mFile.toString(); private List<String> FindFiles() { final List<String>

Restoring SQLite DB file

左心房为你撑大大i 提交于 2019-11-29 00:34:34
I'm implementing a backup/restore system in my android app. An automatic backup occures every couple of minutes. I'm trying to restore my db backup file from my sd card, after my app was uninstalled and then installed again. Backup works, but here's the problem: Whenever the user installs my app again, there's a file not found exception, but, if the user closes the app, and then opens it again, the restore is just fine. Somehow, the restoring faces problem when the app is first launched. The restore must happen on first time launch. Note: the backupExists function returns true. @Override

I want to set an image saved on sd card in main layout background through my application

久未见 提交于 2019-11-28 22:06:07
i am creating an application in which i want set different background images in main xml linearlayout.I have stored 5 image files on sd card .now i want to select a pic and set it as my maim xml linearlayout background.so it will replace the previous image and display the new image as background. First assign an id to the main xml linearlayout, for example in the following case it is named" container" <!-- main.xml --> <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent"

How To Add Media To MediaStore on Android 4.4 KitKat SD Card With Metadata

六眼飞鱼酱① 提交于 2019-11-28 22:01:51
Background: In Android 4.4, Google decided that apps should not have write access to SD cards . However, apps can write to /SDCard/Android/data/App Package Name. So this is what I've done. I have written an MP3 file to /Android/data/. I then want this MP3 file to show up in Android music players. I've tried the following... sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" + filePath))); and.... MediaScannerConnection.scanFile(this, new String[] { file.toString() }, new String[] {"audio/*"}, new MediaScannerConnection.OnScanCompletedListener() { public void

Format SD card in Android

不打扰是莪最后的温柔 提交于 2019-11-28 21:52:59
Things should be simple, but as most of the time, in Android, aren't. I need to format the SD card if the user selects the option in my app. Don't ask me why I need to do this if it's already in the OS... not practical but it's a requirement that I need to implement. As you may know, there is an option in Settings \ Storage \ Erase SD Card . I took a look at the froyo source code and it's something like: final IMountService service = IMountService.Stub.asInterface(ServiceManager.getService("mount")); if (service != null) { new Thread() { public void run() { try { service.formatVolume