android-file

Using Dropbox API to upload a file with Android

混江龙づ霸主 提交于 2019-11-28 06:26:13
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.putFile("/testing_123456.txt", inputStream, fileContents.length(), null, null); } catch

Playing audio file from Sdcard

断了今生、忘了曾经 提交于 2019-11-28 01:22:12
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 possible Use the code below it worked for me. MediaPlayer mp = new MediaPlayer(); mp.setDataSource("/mnt

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

本小妞迷上赌 提交于 2019-11-27 20:03:14
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"/> But I don't know why it could not create the folder. I also used mkdir() step by step but the result is

Save bitmap to file function

那年仲夏 提交于 2019-11-27 20:02:36
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(); System.gc(); Error log: 06-29 00:16:38.089: D/AndroidRuntime(3260): Shutting down VM 06-29 00:16:38

Android: Open file with intent chooser from URI obtained by Storage Access Framework

不打扰是莪最后的温柔 提交于 2019-11-27 17:41:12
问题 In the beginning the user can select files with the new Storage Access Framework (Assuming the app is API>19): https://developer.android.com/guide/topics/providers/document-provider.html Then I save references to those chosen files by saving the URI`s which looks like: content://com.android.providers.downloads.documments/document/745 (in this case the file is from the default downloads dir`). Later, I want let the user to open those files (For example they names displayed in UI list, and the

Android - Copy files from assets to /data/data folder

南楼画角 提交于 2019-11-27 16:23:43
问题 I need to use some files in my app. They are kept in asset folder. I saw discussions on SO, where the files are being copied from asset folder, to /data/data/ on the internal storage, and then being used. I get the code, but what I do not get is, what is the need to copy the assets to internal storage ? If anybody has experience with this, help ! 回答1: One reason that just popped up for me is when using existing C/C++ code with NDK that requires a path to a file and you don't want to modify

Android - How to get selected file name from the document

╄→尐↘猪︶ㄣ 提交于 2019-11-27 14:32:06
问题 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

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

无人久伴 提交于 2019-11-27 13:46:35
问题 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

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

拈花ヽ惹草 提交于 2019-11-27 13:43:16
问题 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(),

Read/write file to internal private storage

我怕爱的太早我们不能终老 提交于 2019-11-27 13:28:26
问题 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