android-file

Save Bitmap in Android as JPEG in External Storage in a folder

两盒软妹~` 提交于 2019-11-28 23:13:46
I am using this code to save Bitmap in External Storage but it does not create the folder if it not exists: String path = Environment.getExternalStorageDirectory().toString(); OutputStream fOutputStream = null; File file = new File(path + "/Captures/", "screen.jpg"); try { fOutputStream = new FileOutputStream(file); capturedBitmap.compress(Bitmap.CompressFormat.JPEG, 100, fOutputStream); fOutputStream.flush(); fOutputStream.close(); MediaStore.Images.Media.insertImage(getContentResolver(), file.getAbsolutePath(), file.getName(), file.getName()); } catch (FileNotFoundException e) { e

Android - How to get selected file name from the document

半世苍凉 提交于 2019-11-28 23:09:42
I am launching the intent for selecting documnets using following code. private void showFileChooser() { Intent intent = new Intent(Intent.ACTION_GET_CONTENT); intent.setType("*/*"); intent.addCategory(Intent.CATEGORY_OPENABLE); try { startActivityForResult( Intent.createChooser(intent, "Select a File to Upload"), 1); } catch (android.content.ActivityNotFoundException ex) { // Potentially direct the user to the Market with a Dialog Toast.makeText(this, "Please install a File Manager.", Toast.LENGTH_SHORT).show(); } } In onActivity results when i am trying to get the file path it is giving some

Load a file from external storage to Inputstream

余生长醉 提交于 2019-11-28 22:52:25
问题 i have a video file in my external directory. how can i load it to inputstream variable. For the time being i am reading file in the res/raw folder but i want to read it from the sdcard. also i dont know about the name of the file but its path will be recieved through intent. check the following code public class SonicTest extends Activity { VideoView videoView; String uri; InputStream soundFile; File file; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate

Where are Android Emulator Image Stored?

℡╲_俬逩灬. 提交于 2019-11-28 22:23:06
问题 On the emulator, I downloaded an image from Google. I can find the image on the emulator, but I have no idea what the file location of the image is. To debug my app I need to know where that image is. How can I get the full path of the image? 回答1: From the AVD documentation: By default, the android tool creates the AVD directory inside ~/.android/avd/ (on Linux/Mac), C:\Documents and Settings\<user>\.android\ on Windows XP, and C:\Users\<user>\.android\ on Windows 7 and Vista. 回答2: If your

java.io.filenotfoundexception open failed eacces (permission denied) on device

我与影子孤独终老i 提交于 2019-11-28 21:27:56
The following code which consists of downloading a file from a server and save it in the storage works fine when the device has an internal storage. But when I tried it with a device with no internal storage, only with external storage I get the following exception. java.io.filenotfoundexception open failed eacces (permission denied) public void downloadFile(String dlUrl, String dlName) { int count; HttpURLConnection con = null; InputStream is = null; FileOutputStream fos = null; try { URL url = new URL( dlUrl ); con = (HttpURLConnection) url.openConnection(); con.setDoInput(true); con.connect

Implementing a File Picker in Android and copying the selected file to another location

谁说我不能喝 提交于 2019-11-28 21:26:09
I'm trying to implement a File Picker in my Android project. What I've been able to do so far is : Intent chooseFile; Intent intent; chooseFile = new Intent(Intent.ACTION_GET_CONTENT); chooseFile.setType("*/*"); intent = Intent.createChooser(chooseFile, "Choose a file"); startActivityForResult(intent, PICKFILE_RESULT_CODE); And then in my onActivityResult() switch(requestCode){ case PICKFILE_RESULT_CODE: if(resultCode==-1){ Uri uri = data.getData(); String filePath = uri.getPath(); Toast.makeText(getActivity(), filePath, Toast.LENGTH_LONG).show(); } break; } This is opening a file picker, but

Read/write file to internal private storage

◇◆丶佛笑我妖孽 提交于 2019-11-28 20:51:18
I'm porting the application from Symbian/iPhone to Android, part of which is saving some data into file. I used the FileOutputStream to save the file into private folder /data/data/package_name/files : FileOutputStream fos = iContext.openFileOutput( IDS_LIST_FILE_NAME, Context.MODE_PRIVATE ); fos.write( data.getBytes() ); fos.close(); Now I am looking for a way how to load them. I am using the FileInputStream , but it allows me to read the file byte by byte, which is pretty inefficient: int ch; StringBuffer fileContent = new StringBuffer(""); FileInputStream fis = iContext.openFileInput( IDS

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

Null pointer Exception on file- URI?

假如想象 提交于 2019-11-28 12:23:55
In my app a capture button is there to capture an image using device camera,so I have used a method captureImage() on the click event of that button.When I click the button a null pointer exception is thrown.I could not understand how this happens Can anyone help? Thanks in advance! capture button on on Create () method photoButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { /* Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); startActivityForResult(cameraIntent, CAMERA_REQUEST);*/ captureImage(); } }); captureImage(

Unable to create a folder programatically

拜拜、爱过 提交于 2019-11-28 12:23:49
问题 Below is the code that I'm using String root = Environment.getExternalStorageDirectory().getAbsolutePath().toString(); File filepathname = new File(root+"/newfolder"); if(filepathname.mkdir()) Toast.makeText(this,"directory created", Toast.LENGTH_SHORT).show(); else Toast.makeText(this,"directory not created", Toast.LENGTH_SHORT).show(); I tried this code in Moto E (running Lollipop) and Nexus 5 (running marshmallow). Folder gets created in Moto but not in Nexus 5. I have been able to create