android-file

Android, how do can I get a list of all files in a folder?

…衆ロ難τιáo~ 提交于 2019-11-27 07:06:38
I need the name (String) of all files in res/raw/ I tried: File f = new File("/"); String[] someFiles = f.list(); It looks like the root directory is the root of the android emulator...and not my computers root directory. That makes enough sense, but doesn't really help me find out where the raw folder exists. Update: Thanks for all the great replies. It appears that some of these are working, but only getting me half way. Perhaps a more detailed description will aid I want to get all the mp3 files in the raw folder so I can get all the names, then add them to a URI to play a random MP3 in the

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")

Android: mkdirs()/mkdir() on external storage returns false

本小妞迷上赌 提交于 2019-11-27 04:25:16
问题 I'm driven crazy with this: Log.d("STATE", Environment.getExternalStorageState()); File f = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM), "work_data"); Log.d("PATH", f.getAbsolutePath()); if (!f.exists()) { Log.d("MAKE DIR", f.mkdirs() + ""); } The output log looks like this: STATE mounted PATH /mnt/sdcard/DCIM/work_data MAKE DIR false I made sure to add the correct permission: <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

Using Dropbox API to upload a file with Android

巧了我就是萌 提交于 2019-11-27 01:20:48
问题 How can I upload a File (graphic, audio and video file) with Android using the Dropbox API to Dropbox? I followed the tutorial on the Dropbox SDK Android page and could get the sample to work. But now instead of a String I want to upload an actual File object and am struggling. The sample code works without any problems and looks like this: String fileContents = "Hello World!"; ByteArrayInputStream inputStream = new ByteArrayInputStream(fileContents.getBytes()); try { Entry newEntry = mDBApi

How to Copy Image File from Gallery to another folder programmatically in Android

时间秒杀一切 提交于 2019-11-27 01:20:46
问题 I want to pick image from gallery and copy it in to other folder in SDCard. Code to Pick Image from Gallery Intent photoPickerIntent = new Intent(Intent.ACTION_PICK); photoPickerIntent.setType("image/*"); startActivityForResult(photoPickerIntent, REQUEST_CODE_CHOOSE_PICTURE_FROM_GALLARY); I get content://media/external/images/media/681 this URI onActivityResult. I want to copy the image, Form path ="content://media/external/images/media/681 To path = "file:///mnt/sdcard/sharedresources/ this

Difference between mkdir() and mkdirs() in java for java.io.File [closed]

前提是你 提交于 2019-11-27 00:07:30
问题 Can anyone tell me the difference between these two methods: file.mkdir() file.mkdirs() 回答1: mkdirs() also creates parent directories in the path this File represents. javadocs for mkdirs() : Creates the directory named by this abstract pathname, including any necessary but nonexistent parent directories. Note that if this operation fails it may have succeeded in creating some of the necessary parent directories. javadocs for mkdir() : Creates the directory named by this abstract pathname.

Simple mediaplayer play mp3 from file path?

我是研究僧i 提交于 2019-11-26 22:38:32
I have a very simple mediaplayer that play background. It calls file from the apk, but I want it to play from any directory like as music or sdcard. Here are my codes: private MediaPlayer mpintro; . . mpintro = MediaPlayer.create(this, R.raw.intro); mpintro.setLooping(true); mpintro.start(); It works like this: mpintro = MediaPlayer.create(this, Uri.parse(Environment.getExternalStorageDirectory().getPath()+ "/Music/intro.mp3")); mpintro.setLooping(true); mpintro.start(); It did not work properly as string filepath... String filePath = Environment.getExternalStorageDirectory()+"/yourfolderNAme

Trying to create a file in Android: open failed: EROFS (Read-only file system)

匆匆过客 提交于 2019-11-26 20:28:33
This line: final FileOutputStream outputStream = new FileOutputStream(name); results in a FileNotFoundException with the message being /2ozjfFQzwv: open failed: EROFS (Read-only file system) where "2ozjfFQzwv" is what I passed as the name of the file. I have tried this with and without the WRITE_INTERNAL_STORAGE permission. How do I create this file for writing? Alternatively, I just want to be able to give an image to a new activity, and it is too large to serialize it in an extra. Is there an easier way than writing it to a file then reading from it again? All the questions on here seem to

Save bitmap to file function

风格不统一 提交于 2019-11-26 20:07:05
问题 I'm trying to save a bitmap to file and a specific directly using a function I've created. It's not working. It crashes after bitmap.compress part (before here3). File dir = new File(filepath); if(!dir.exists())dir.mkdirs(); File file = new File(Environment.getExternalStorageDirectory() + filepath, side + ".png"); FileOutputStream fOut = new FileOutputStream(file); bitmap.compress(Bitmap.CompressFormat.PNG, 85, fOut); fOut.flush(); fOut.close(); System.out.println(filepath); bitmap.recycle();

Playing audio file from Sdcard

你。 提交于 2019-11-26 17:22:20
问题 I would like to play an audio file from the sdcard. How can I read the audio file and play it? Below is my code to play audio file: int sound1; sound1 = mSoundPool.load(this, R.raw.om, 1); mSoundPool.play(sound1, 1, 1, 1, time - 1, 1); Here in the above code i am using soundpool to play the audio file from raw folder but i need to play the audio file from sdcard using soundpool. Right now interested to play audio from sdcard. How to acheive this? please help i need to fix this as soon as