android-sdcard

How to get random access to a file on SD-Card by means of API presented for Lollipop?

◇◆丶佛笑我妖孽 提交于 2019-11-28 21:41:50
My application uses Java class RandomAccessFile to read/write bytes to a file on SD card randomly by means of realization of SeekableByteChannel interface. Now I need rewrite it for Android 5.0 with new Lollipop API. I have found the only way to read: InputStream inputStream = getContentResolver().openInputStream(uri); and write: ParcelFileDescriptor pfd = getActivity().getContentResolver().openFileDescriptor(uri, "w"); FileOutputStream fileOutputStream = new FileOutputStream(pfd.getFileDescriptor()); from/to a file in new API. I would like to have an ability to set channel in some random

Check if directory exist on android's sdcard

╄→尐↘猪︶ㄣ 提交于 2019-11-28 20:47:09
问题 How do I check if a directory exist on the sdcard in android? 回答1: Regular Java file IO: File f = new File(Environment.getExternalStorageDirectory() + "/somedir"); if(f.isDirectory()) { .... Might also want to check f.exists() , because if it exists, and isDirectory() returns false, you'll have a problem. There's also isReadable() ... Check here for more methods you might find useful. 回答2: File dir = new File(Environment.getExternalStorageDirectory() + "/mydirectory"); if(dir.exists() && dir

MediaStore.Images.Media.insertImage is returning null when trying to save the image

喜夏-厌秋 提交于 2019-11-28 20:29:48
I am using an custom view and in that i am using an canvas in which a user can draw anything and after that i want to save that image in sd card bt was not able to do that. Don't know what is going on. else if(view.getId()==R.id.save_btn){ //save drawing AlertDialog.Builder saveDialog = new AlertDialog.Builder(this); saveDialog.setTitle("Save drawing"); saveDialog.setMessage("Save drawing to device Gallery?"); saveDialog.setPositiveButton("Yes", new DialogInterface.OnClickListener(){ private FileOutputStream fOut; public void onClick(DialogInterface dialog, int which){ //save drawing drawView

Copy files from a folder of SD card into another folder of SD card

≯℡__Kan透↙ 提交于 2019-11-28 17:56:09
Is it possible to copy a folder present in sdcard to another folder present the same sdcard programmatically ?? If so, how to do that? An improved version of that example: // If targetLocation does not exist, it will be created. public void copyDirectory(File sourceLocation , File targetLocation) throws IOException { if (sourceLocation.isDirectory()) { if (!targetLocation.exists() && !targetLocation.mkdirs()) { throw new IOException("Cannot create dir " + targetLocation.getAbsolutePath()); } String[] children = sourceLocation.list(); for (int i=0; i<children.length; i++) { copyDirectory(new

How to get access to all SD-cards, using the new Lollipop API?

Deadly 提交于 2019-11-28 17:53:26
background Starting with Lollipop, apps can get access to real SD-cards (after it was not accessible on Kitkat, and was not officially supported yet worked on previous versions), as I've asked about here . The problem Because it has become quite rare to see a Lollipop device that supports SD-card and because the emulator doesn't really has the ability (or does it?) to emulate an SD-card support, it took me quite a while to test it. Anyway, it seems that instead of using the normal File classes to access the SD-card (once you got a permission for it), you need to use Uris for it, using

Saving Logcat to a text file in Android Device

余生颓废 提交于 2019-11-28 16:14:19
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? 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. after that the logcat output is cleared and the new logcat output is written into a new file called

How do i adb pull ALL files of a folder present in SD Card

邮差的信 提交于 2019-11-28 15:29:56
I have a folder in my SD Card as: /mnt/sdcard/Folder1/Folder2/Folder3/*.jpg The name of Folder1 and Folder2 remains constant and inside Folder2 i have Folder3, 4, 5 and so on.. i want to pull all the jpeg files rather all files (there are more) using adb to my current directory on the computer.. Every folder has different number of jpeg files and other files and i tried using this: adb pull mnt/sdcard/Folder1/Folder2/Folder/*.jpg . But it didnt work.. So uhmm how do i adb pull all files present in any folder of SD Card with a single command (single command because each folder has different

Saving files on external storage on Nexus 7 and retrieving from PC

为君一笑 提交于 2019-11-28 12:30:10
For my project I want to be able to save sensor data to a file, and be able to access it from a PC for further analysis. This is the code I have so far and it works successfully: File root = Environment.getExternalStorageDirectory(); File csvfile = new File(root, "Sensor_Data.csv"); FileWriter writer = new FileWriter(csvfile, true); writer.append("Time"); writer.append(','); writer.append("Position"); writer.append('\n'); Number data[] = new Number[4000]; for (int i = 0; i<4000; i+=2){ posHistory.toArray(data); writer.append(String.valueOf(data[i])); writer.append(','); writer.append(String

How to delete entire contents of sdcard programmatically in Android 2.2

微笑、不失礼 提交于 2019-11-28 11:42:43
I wish to delete the users entire SDcard programmatically in Android 2.2. What is the easiest way to do this? Will it require root rights? Can I just do an "rm -rf /mnt/sdcard" or do I have to make a recursive loop? Peter Knego You can delete directories with Java. You have to do it recursively if they are not empty: http://www.exampledepot.com/egs/java.io/DeleteDir.html No. All applications have full RW access to external storage. Yes you can execute shell commands (but you'll have to check if "rm" is available): Any way to run shell commands on android programmatically? Checking for

How can I display image in Android Application

本秂侑毒 提交于 2019-11-28 10:13:06
I want to display Image in my Android application in specific size. How can I do it? Please guide me? And one more thing I want that image from SD card. So please Help me. Thanks in advance. Bharat Sharma First you need to create an imageview. ImageView imageView = new ImageView(getApplicationContext()); Create layout param to add imageview on layout LayoutParams lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); Then get your image path String path = Environment.getExternalStorageDirectory() + "/your folder name/image_name.bmp"; Set your image on ImageView Bitmap