sd-card

Loading drawable from sd card

﹥>﹥吖頭↗ 提交于 2019-11-27 18:30:45
问题 I'm trying to load a png image as a drawable from my device sd card. I use the following function but it doesn't work: public Drawable getDrawable() { return new BitmapDrawable(imagePath); } The image path is: mnt/sdcard/MyFolder/image.png The app crashes when I try calling that method, how should I load my png image located in my sdcard and cast it into a Drawable object? 回答1: There is actually a BitmapDrawable constructor straight from file path. The method you are using is depricated. Try:

Removable storage (external) sdcard path by manufacturers

我是研究僧i 提交于 2019-11-27 18:09:02
I've been Googling around but it is sooooo hard to find what manufacturers/models use which path for sdcard/external storage. I am NOT talking about the internal storage path which can be found by: Environment.getExternalStorageDirectory() I know that getExternalStorageDirectory() sometimes points to external sdcard on some devices. Here's what I've found some common path for external path (Not sure which manufacturer uses which path): /emmc /mnt/sdcard/external_sd /mnt/external_sd /sdcard/sd /mnt/sdcard/bpemmctest /mnt/sdcard/_ExternalSD /mnt/sdcard-ext /mnt/Removable/MicroSD /Removable

How can I programmatically format all data on an SD Card?

試著忘記壹切 提交于 2019-11-27 17:01:47
问题 How can I programmatically delete data or format the entire SD Card? 回答1: code to wipe SDCARD public void wipingSdcard() { File deleteMatchingFile = new File(Environment .getExternalStorageDirectory().toString()); try { File[] filenames = deleteMatchingFile.listFiles(); if (filenames != null && filenames.length > 0) { for (File tempFile : filenames) { if (tempFile.isDirectory()) { wipeDirectory(tempFile.toString()); tempFile.delete(); } else { tempFile.delete(); } } } else {

It is possible to get total storage capacity?

做~自己de王妃 提交于 2019-11-27 15:19:39
i know how to get free capacity on internal memory and on external storage. But i want to know max capacity of internal memory and max capacity of external storage, but i can't find any info about it on google it is possible to achieve it? thanks StatFs stat = new StatFs(Environment.getExternalStorageDirectory().getPath()); long bytesAvailable = (long)stat.getBlockSize() * (long)stat.getBlockCount(); long megAvailable = bytesAvailable / 1048576; Source Also, use this for internal size. StatFs stat = new StatFs(Environment.getDataDirectory().getPath()); Some new methods were introduced in API

How to check if newly created folder is present into SD Card in Android

十年热恋 提交于 2019-11-27 15:06:36
问题 From my application, I want to store some images into my SD card. For that I need to create a one folder. At the first time folder will create but after it checks whether that folder is present or not. How can I do it? 回答1: below code will create a directory if it does not exist File direct = new File(Environment.getExternalStorageDirectory() + "/New Folder"); if(!direct.exists()) { if(direct.mkdir()) { //directory is created; } } 回答2: You should request the following permission first in your

Eclipse console shows:'Failed to push selection: Read-only file system'when i try to push a file

*爱你&永不变心* 提交于 2019-11-27 14:24:18
问题 I am trying to push a file to the SD Card but its showing error in console 'failed to push selection: Read-only file system'.I am using DDMS perspective in Eclipse.I generated sdcard using mksdcard command. 回答1: Just go to C:\Documents and Settings\<adminstrator>\.android\avd take 'properties' of your avd folder (there is a folder for each of the avd's) uncheck 'Read only' -> OK This was the only thing that worked for me. P.S: Some of these folders might be hidden. 回答2: On the Terminal or

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

♀尐吖头ヾ 提交于 2019-11-27 13:49:01
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. Sheharyar Add a Method GetFiles() to your program. Call it to get an ArrayList<> of all the files. You can then use it to populate your listview . You need to provide String argument DirectoryPath . The Function: public

Display all music on SD card [closed]

▼魔方 西西 提交于 2019-11-27 11:23:14
问题 I'm using code form this page: http://z4android.blogspot.com/2011/06/displaying-list-of-music-files-stored.html The code is working, but not soo good. When I'm trying to scroll down, the ListView keeps repeating the songs in the list. I have been looking for some alternative code, but I have not found any. Thanks for any help. 回答1: I'm not entirely sure exactly what causes the problems you mention, but try this code. private MediaPlayer mMediaPlayer; private String[] mMusicList; /** Called

SQLiteOpenHelper - creating database on SD card

天涯浪子 提交于 2019-11-27 09:20:02
in my test android app I intend to create and access database file, which will be located on SD card. I am using main activity with help of a class, which extends SQLiteOpenHelper. I want to use it the same way as before, but I have to somehow change the database PATH. Do you know, how to achieve it? thx My current code of a class which extends SQLiteOpenHelper: public class DatabaseDefinition extends SQLiteOpenHelper{ private static final String DATABASE_NAME="test.db"; private static final int DATABASE_VERSION=1; public DatabaseDefinition(Context context) { super(context,DATABASE_NAME,null,

android intent for sdcard ready

青春壹個敷衍的年華 提交于 2019-11-27 08:39:14
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(this.mSDInfoReceiver, new IntentFilter(filter)); and create a broadcast receiver to react to it: private