android-sdcard

Android: remove an image from sd card

随声附和 提交于 2019-12-18 15:10:04
问题 I need to remove an image from sd card chosen by user. In my Activity, after an user select an image from gallery, i execute this code: public void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == RESULT_OK) { if (requestCode == SELECT_PICTURE) { Utils.imgUri = data.getData(); Utils.imgPath = getPath(Utils.imgUri); File file = new File(Utils.imgPath); boolean deleted = file.delete(); } } } where getPath method is: public String getPath(Uri uri) { String[]

Android - Saving a downloaded image from URL onto SD card

自古美人都是妖i 提交于 2019-12-18 12:37:52
问题 I am loading an image from an URL on button click, and storing it as a Bitmap. Now i want to know how to save that downloaded image into sd card as well as in system. I attempted to do it the following way: package com.v3.thread.fetchImage; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; import android.app.Activity; import android

Building a Utility to get the path to External Removable storage every time

折月煮酒 提交于 2019-12-18 05:07:10
问题 Recently, I needed to be able to write some data strictly on a phone's external, removable storage (aka SDCard). For lower-end devices without "external" internal storage (you know what I mean), this isn't an issue as Environment.getExternalStorageDirectory().getAbsolutePath() , which returns /mnt/sdcard is also the path to the sdcard. However on higher-end phones with built-in flash storage (sgs 2 for example), /mnt/sdcard , which is returned from Environment.getExternalStorageDirectory()

mkdirs returns false for directory on sd card while the parent directory is writable

早过忘川 提交于 2019-12-18 04:31:52
问题 When starting my android application, I need to create a directory on the sd card, for a small number of users this fails and I can't figure out the reason for it... (I've found similar problems caused by the WRITE_EXTERNAL_STORAGE permission missing, it's there and it works for almost all users so I don't think this is reason) I've simplified the previous situation to make it easier to explain, if creating a directoy fails, I run a test case where I try to make a .test directory on the

How to get the internal and external sdcard path in android

青春壹個敷衍的年華 提交于 2019-12-18 03:09:04
问题 Most of the new android devices have an internal sdcard and an external sdcard. I want to make a file explorer app but I can't find out how to get the path to use in my app because File file = Environment.getExternalStorageDirectory(); just returns in most device /mnt/sdcard but there is another path for the other external sdcard like /storage1 or /storage2 . Any help appreciated. 回答1: How to get the internal and external sdcard path in android Methods to store in Internal Storage: File

How to get all image files available in sdcard in android? [duplicate]

允我心安 提交于 2019-12-18 03:03:46
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: How to get all the pictures from the sdcard of emulator and display it in a listView? I have so many folders under sdcard. Each folder contains image files, text files and sub folders. How do i get all image files available in all folders & subfolders under sdcard? I need to store all image file paths into one array. Can anyone help me please. 回答1: You can use below code to search all image from SD Card .

Saving to SD card as text file

二次信任 提交于 2019-12-17 23:35:04
问题 stopWriting = (Button) findViewById(R.id.save); stopWriting.setOnClickListener(new OnClickListener() { @SuppressLint("SdCardPath") public void onClick(View v) { // stop recording the sensor data try { myFile = new File("/sdcard/SensorData/" + txtData.getText() + ".txt"); myFile.createNewFile(); sData = new FileOutputStream(myFile); myOutWriter = new OutputStreamWriter(sData); myBufferedWriter = new BufferedWriter(myOutWriter); myPrintWriter = new PrintWriter(myBufferedWriter); //if(myFile !=

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

ⅰ亾dé卋堺 提交于 2019-12-17 22:34:26
问题 Is it possible to copy a folder present in sdcard to another folder present the same sdcard programmatically ?? If so, how to do that? 回答1: 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()

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

久未见 提交于 2019-12-17 22:15:10
问题 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

storing android application data on SD Card

≯℡__Kan透↙ 提交于 2019-12-17 17:33:48
问题 Is there a way to store android application data on the SD card instead of in the internal memory? I know how to transfer the application sqlite database from the internal memory to the SDCard, but what if the internal memory gets full in the first place? How does everyone handle this? 回答1: Warning: This answer is out-dated. You should use Environment.getExternalStorageDirectory() to get the root path of the SD card as mentioned in the answers below. Old Answer so the comments on this make