android-sdcard

Saving Logcat to a text file in Android Device

梦想与她 提交于 2019-11-27 05:07:36
问题 I had found some crashes while running the application in android device, which is not showing in emulator. So i need to save the Logcat in a text file in my device's memory or SD card. Could you please suggest me good method to do this? 回答1: use a Application class at the beginning of your app. That allows a proper file and log handling. Here is an example. That piece of code adds a new folder named “MyPersonalAppFolder” with another folder called “log” in it to the public external storage.

Writing Text File to SD Card fails

蓝咒 提交于 2019-11-27 04:40:46
I have a strange problem I've come across. My app can write a simple textfile to the SD Card and sometimes it works for some people but not for others and I have no idea why. For some people, it force closes if they put some characters like ... in the File and such. I cannot seem to reproduce it as I've had no troubles but this is the code which handles the File writing. Can anyone think of something that may lead to problems or a better to way to do it? public void generateNoteOnSD(String sFileName, String sBody) { try { File root = new File(Environment.getExternalStorageDirectory(), "Notes")

Getting all the total and available space on Android

 ̄綄美尐妖づ 提交于 2019-11-27 04:32:52
To my knowledge, on Android, there is: Internal memory for apps and cache Internal SD Card on some phones (not removable) External SD Card for music and photos (removable) How do I get the total and available for each with a check that they exist (some phones do not have an internal SD Card) Thanks Here is how you get internal storage sizes: StatFs statFs = new StatFs(Environment.getRootDirectory().getAbsolutePath()); long blockSize = statFs.getBlockSize(); long totalSize = statFs.getBlockCount()*blockSize; long availableSize = statFs.getAvailableBlocks()*blockSize; long freeSize = statFs

Why getExternalFilesDirs() doesn't work on some devices?

帅比萌擦擦* 提交于 2019-11-27 03:27:04
问题 My app runs on Android 5.0. I use method getExternalFilesDirs() to check if external SD card is available. If it returns more than 1 File , that means external SD card exists. But on some devices (for example Elephone G2), method getExternalFilesDirs() returns only one directory of primary storage. I'm sure that device has external SD card (/storage/sdcard1/). Can any one give me the answer? 回答1: For getExternalFilesDirs to return the path of the sdcard, the OEM must have set the SECONDARY

Android - Save images in an specific folder

有些话、适合烂在心里 提交于 2019-11-27 03:25:43
I need to save the pictures taken with my app in an specific folder. I've read many solutions to this problem but I couldn't make any of them work so I ask for help. MainActivity.java public void onClick(View v) { Intent camera = new Intent( android.provider.MediaStore.ACTION_IMAGE_CAPTURE); //Folder is already created String dirName = Environment.getExternalStorageDirectory().getPath() + "/MyAppFolder/MyApp" + n + ".png"; Uri uriSavedImage = Uri.fromFile(new File(dirName)); camera.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage); startActivityForResult(camera, 1); n++; } AndroidManifest.xml

Observing changes in Android content observer for Audio.Media.EXTERNAL_CONTENT_URI

时光总嘲笑我的痴心妄想 提交于 2019-11-27 02:50:57
问题 I am developing an Android app in which I have to detect changes in Android SD card for audio files with the file name, file path and operation performed upon it. Example if I am adding a file in my SD card then I want to know Name of the file which is added Path of the file Operation -- Add Previously I Have tried file observer But for that I have to apply it on each and every directory. So I searched for some other solution and got the info about Audio.Media.EXTERNAL_CONTENT_URI . Then I

External SDCard file path for Android

天大地大妈咪最大 提交于 2019-11-27 02:17:58
问题 Is it true that the file path to external SDCard on Android devices are always "/storage/extSdCard" ? If not, how many variations are there? I need it for my App to test the availability of external SDCard. I am using Titanium, it has a method Titanium.Filesystem.isExternalStoragePresent( ) but it always return true even external SDCard is not mounted. I think it detect SDCard at local storage thus return true. But what I really want is detect whether physical SDCard is mounted or not. Can I

Copying raw file into SDCard?

随声附和 提交于 2019-11-27 02:08:11
I've some audio files in my res/raw folder. For some reasons, i want to copy this files to my SDCard When, my application starts. How can i done this? Anyone guide me? Nikolay Elenkov Read from the resource, write to a file on the SD card: InputStream in = getResources().openRawResource(R.raw.myresource); FileOutputStream out = new FileOutputStream(somePathOnSdCard); byte[] buff = new byte[1024]; int read = 0; try { while ((read = in.read(buff)) > 0) { out.write(buff, 0, read); } } finally { in.close(); out.close(); } Copy file from raw to External Storage: This is a method that i use to do

SDCard content exist but cant see them

点点圈 提交于 2019-11-27 02:03:11
I am having very Strange problem with my Samsung Nexus with Android 4.0.2. I wrote a simple program which basically create file each time user presses a button. My program is working great on other devices where as on Galaxy Nexus Windows/Mac can not see those files on SD card, but when i do adb shell i see all files on SD Card. I retest this on another Nexus which has Android 4.0.4 but still same result. What could be the reason? You probably need to index your files via MediaScannerConnection . Quoting myself from a blog post from last year : ...the MTP contents are not based on the literal

Check if the SDCard is present, boolean is always true

守給你的承諾、 提交于 2019-11-27 01:21:22
In my splash screen, I want to check if the phone has a SDCard. The Boolean statement is beneath: Boolean isSDPresent = android.os.Environment.getExternalStorageState() .equals(android.os.Environment.MEDIA_MOUNTED ); So, if I have the SDCard in the slot on my phone, this boolean will return true, so far so good. When I go to the "Unmount SDCard" from the settings menu, and removes the SDCard, then kill the app and launching it again, the boolean will also be true.. And if I launches the Astro File Manager after unmounting and removing the sdcard, I can still access the /mnt/sdcard path, why?