sd-card

How to display files on the SD card in a ListView?

99封情书 提交于 2019-11-26 16:29:34
问题 I would like to create a button that when clicked will go to a class that displays all media files from an SD card using a ListView . After selecting from the list it will then return the filename selected to the main class. IF the returned file is an image file, it will be displayed in an ImageView and if the returned file is an audio file, it'll just display an icon. 回答1: Add a Method GetFiles() to your program. Call it to get an ArrayList<> of all the files. You can then use it to populate

android intent for sdcard ready

最后都变了- 提交于 2019-11-26 14:14:29
问题 I have an application that uses a file on the SD card, the application runs when the phone boots, and it has become apparent that the file cannot be accessed when the program is first run as it starts working before SD card is avaliable. Is there an broadcast receiver I can use to tell when the SD card is ready? Update Just to summarise the answer to register the intent do: IntentFilter filter = new IntentFilter (Intent.ACTION_MEDIA_MOUNTED); filter.addDataScheme("file"); registerReceiver

Delete a folder on SD card

Deadly 提交于 2019-11-26 09:34:54
问题 I tried File.delete() but it doesn\'t work. How to delete a directory on SD card? I\'m working on Android 2.1. 回答1: You have to have all the directory empty before deleting the directory itself, see here In Android, you should have the proper permissions as well - WRITE_EXTERNAL_STORAGE in your manifest. EDIT: for convenience I copied the code here, but it is still from the link above public static boolean deleteDirectory(File path) { if( path.exists() ) { File[] files = path.listFiles(); if

How to save file from website to sdcard

眉间皱痕 提交于 2019-11-26 08:06:02
问题 Does anyone know how to save a file from a webserver(local host) to the sdcard through wifi? I am doing xml parsing to my application and for that I have to download an xml file from localhost to the sdcard and then tag the parsing. I am stuck with downloading an xml file to the sd card. Please guide me on how to do this.. 回答1: You can use this method to download a file from the internet to your SD card: public void DownloadFromUrl(String DownloadUrl, String fileName) { try { File root =

Unzip a zipped file on sd card in Android application

只愿长相守 提交于 2019-11-26 07:46:00
问题 I have a zipped password protected a video file saved on sd card on android emulator. Now i want to unzip that video file on sd card through code. How can i achieve that? Any help or code? Thanks in advance 回答1: import android.util.Log; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; /** * * @author jon */ public class Decompress { private String _zipFile; private String _location; public

Scan Android SD card for new files

耗尽温柔 提交于 2019-11-26 07:42:30
问题 My app allows a user to save an image to their SD card. But I\'m not sure how to make it appear in the gallery until you unmount and remount the SD card. I have googled for a couple of days with this problem but am not sure how to make it appear automatically. I found this link but I\'m not sure how to use the class. This is what i use to save the file. At the bottom of the try catch block is where I want to scan the sd card for new media. FileOutputStream outStream = null; File file = new

Decoding bitmaps in Android with the right size

扶醉桌前 提交于 2019-11-26 06:19:35
问题 I decode bitmaps from the SD card using BitmapFactory.decodeFile . Sometimes the bitmaps are bigger than what the application needs or that the heap allows, so I use BitmapFactory.Options.inSampleSize to request a subsampled (smaller) bitmap. The problem is that the platform does not enforce the exact value of inSampleSize, and I sometimes end up with a bitmap either too small, or still too big for the available memory. From http://developer.android.com/reference/android/graphics

Android Open External Storage directory(sdcard) for storing file

给你一囗甜甜゛ 提交于 2019-11-26 06:05:35
问题 I want to open external storage directory path for saving file programatically.I tried but not getting sdcard path. How can i do this?is there any solution for this?? private File path = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) + \"\"); or private File path = new File(Environment.getExternalStorageDirectory() + \"\"); I tried getting path from above both methods but both are pointing internal memory. When we open storage memory if sdcard is

Check whether the SD card is available or not programmatically

北城以北 提交于 2019-11-26 05:29:04
问题 My app is working for mobiles which have an SD card only. So programmatically I want to check if the SD card is available or not and how to find the SD card free space. Is it possible? If yes, how do I do it? 回答1: Boolean isSDPresent = android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED); Boolean isSDSupportedDevice = Environment.isExternalStorageRemovable(); if(isSDSupportedDevice && isSDPresent) { // yes SD-card is present } else { // Sorry } 回答2:

How do I backup a database file to the SD card on Android?

痞子三分冷 提交于 2019-11-26 01:44:59
问题 I\'d like to add a feature to my Android app that automatically backs up the SQLite database to the SD card. What\'s the best way to go about this? Are any examples or tutorials available? 回答1: SQLite databases are completely self-contained files and are portable — you can just copy the entire file straight to the SD card. Though first I'd check whether an SD card is installed in the device, and what its path is (using Environment.getExternalStorageDirectory() ). 回答2: This code works for me!