android-sdcard

How to check if a file exists in a directory in sd card

纵饮孤独 提交于 2019-12-04 05:13:11
I want to check whether a given file exists in android sd card. I am trying it out with creating a file using the absolute path and checking with file.exists() but its not working. The URL for the file is "file:///mnt/sdcard/book1/page2.html" and the file does exist. But somehow file.exists() isn't showing the same. File extStore = Environment.getExternalStorageDirectory(); File myFile = new File(extStore.getAbsolutePath() + "/book1/page2.html"); if(myFile.exists()){ ... } This should work. Try like this: File file = new File(Environment.getExternalStorageDirectory() + "/book1/page2.html"); if

Why is AssetManger.list() so slow?

左心房为你撑大大i 提交于 2019-12-04 03:11:14
问题 I'm trying to populate a ListView with a mixture of files stored on the SDcard AND stored as assets in the APK. Using TraceView , I can see that the performance of AssetManager.list() is poor in comparison to File.listFiles() , even though I'm using a filename filter for the SDcard. Here is a simple method that returns all the png files from a folder on the SDcard: // The folder on SDcard may contain files other than png, so filter them out private File[] getMatchingFiles(File path) { File[]

Android Studio music player cant read from sdcard, only internal memory

与世无争的帅哥 提交于 2019-12-03 20:08:28
I apologize if this turns out to be a stupid question, it might turn out as a quick fix but I just cant figure it out. I'm building a music player in android studio and none of the songs on the sdcard dont show up in the list view, only the ones in internal memory, even though I did implement getExternalStorageDirectory() and added the permission in the manifest file. Any input on this or constructive criticism is greatly apreciated. Here is the main java class. public class MainActivity extends AppCompatActivity { ListView lv; String[] items; @Override protected void onCreate(Bundle

Accessing Storage on the Nook

谁都会走 提交于 2019-12-03 16:47:08
The closest thing to documentation I can find having to do with file storage is this post (see below if you can't access it), but it leaves me with several questions. I would really, really, really like a knowledgeable explanation of what paths map to what storage here, seeing as how we're supposed to hard-code them, and how precisely we're expected to access them. An actual code sample would be superlative. My best guess from messing around with this is that: /sdcard-> maps to the internal eMMC slot, and access is restricted. Environment.getExternalStorageDirectory(); ... still returns this.

Get .mp3 format files from android device

橙三吉。 提交于 2019-12-03 16:23:19
I'm developing a music player. I want to get all .mp3 format files from android device. But this code is not getting any files. My .mp3 files are in 'sdcard/music' folder. If i change the MEDIA_PATH = new String("sdcard/music"); like this it's getting files only from that music folder. But i need to get all .mp3 files from each and every folder in my external/internal memorycard. Please help me. this is my code. final String MEDIA_PATH = new String(Environment.getExternalStorageDirectory()); public void Generate_Database(){ File home = new File(MEDIA_PATH); if (home.listFiles(new

How to play mp3 files from internal and external SD card in android?

独自空忆成欢 提交于 2019-12-03 15:42:15
I am working on a mp3 player app, which plays .mp3 files present anywhere inside an internal SD card. I have used the following codes to fetch the .mp3 files present in internal storage. ArrayList<File> inFiles = new ArrayList<File>(); File list[] = file.listFiles(); //Log.i("DIR", "PATH" +file.getPath()); for (int i = 0; i < list.length; i++) { // myList.add( list[i].getName() ); File temp_file = new File(file.getAbsolutePath(),list[i].getName()); //Log.i("DIR", "PATH" +temp_file.getAbsolutePath()); if (temp_file.listFiles() != null) { //Log.i("inside", "call fn"); listfiles(temp_file); }

Is there a way to get SD Card size in Android?

和自甴很熟 提交于 2019-12-03 14:33:28
问题 Welcome all I have tried every question related to this in Stackoverflow and google and none of them works. I have tried something like this next link, but it returns the same as internal storage: How to get an External storage sd card size (With Mounted SD card)? For example, if I have about 12GB internal storage and 4GB SD card storage, no matter what method I use, I always get the exact same number for the SD space as I do for internal space. It seems that the old methods posted here in

Android 2.2 - How do I detect if I am installed on the SDCard or not?

旧巷老猫 提交于 2019-12-03 12:25:41
I am writing an android app that stores a lot of media files. They are not the type (and are far too many) to clutter up the users notification or other media directories, but they also must be user-updatable, so I can't put them in the resources. I can use getExternalFilesDir to get a path on the sdcard, but I only want to do that if the app itself is installed on the sdcard. If the app is installed internally, I want to put the media in the internal memory. So how can I determine if my app is running in internal or external memory? Charlie Collins You could use PackageManager to get the

How to create Android directory automatically if it doesn't already exist

ぐ巨炮叔叔 提交于 2019-12-03 10:52:05
I am creating a gallery app using a tutorial but get the following error: abc directory path is not valid! Please set the image directory name AppConstant.java class Please visit the following link to see the entire tutorial's code as I am using the same code: http://www.androidhive.info/2013/09/android-fullscreen-image-slider-with-swipe-and-pinch-zoom-gestures/ I found this code in Utils Class: else { // image directory is empty Toast.makeText( _context, AppConstant.PHOTO_ALBUM + " is empty. Please load some images in it !", Toast.LENGTH_LONG).show(); } } else { AlertDialog.Builder alert =

How to read OTG USB storage

南楼画角 提交于 2019-12-03 09:02:20
I want to read/write OTG USB storage from device. For that I have written the code below but it shows only the SD card. HashSet<String> out = new HashSet<String>(); String reg = "(?i).*vold.*(vfat|ntfs|exfat|fat32|ext3|ext4).*rw.*"; String s = ""; try { final Process process = new ProcessBuilder().command("mount") .redirectErrorStream(true).start(); process.waitFor(); final InputStream is = process.getInputStream(); final byte[] buffer = new byte[1024]; while (is.read(buffer) != -1) { s = s + new String(buffer); } is.close(); } catch (final Exception e) { e.printStackTrace(); } // parse output