android-sdcard

Cannot Write to sdcard in Android emulator

不羁的心 提交于 2019-12-17 16:34:24
问题 I have added this line in the AndroidManifest.xml: <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> However, when I run code to write to the sdcard , I get this Error: 02-19 13:24:46.760: E/CameraTest(598): /mnt/sdcard/image.jpg: open failed: EACCES (Permission denied) How do I solve this problem? EDIT: I am using the Android Emulator with SDCard added. EDIT-2: I know what the problem is now: I have called the function Environment.getExternalStorageState() and I

Android SD card writing, Permission Denied

情到浓时终转凉″ 提交于 2019-12-17 16:06:03
问题 I am trying to write a file to SDCard with below Code (permission android.permission.WRITE_EXTERNAL_STORAGE already set in manifest.xml). Upon execution of nmea_file.createNewFile(); it throws exception with Permission Denied . Any guesses why would this be happening? if(!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { Log.d(TAG, "Sdcard was not mounted !!" ); } else { File nmea_file; File root = Environment.getExternalStorageDirectory(); FileWriter nmea_writer =

Copying raw file into SDCard?

谁说我不能喝 提交于 2019-12-17 06:51:58
问题 I've some audio files in my res/raw folder. For some reasons, i want to copy this files to my SDCard When, my application starts. How can i done this? Anyone guide me? 回答1: Read from the resource, write to a file on the SD card: InputStream in = getResources().openRawResource(R.raw.myresource); FileOutputStream out = new FileOutputStream(somePathOnSdCard); byte[] buff = new byte[1024]; int read = 0; try { while ((read = in.read(buff)) > 0) { out.write(buff, 0, read); } } finally { in.close();

Simple mediaplayer play mp3 from file path?

╄→尐↘猪︶ㄣ 提交于 2019-12-17 06:12:25
问题 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(); 回答1: 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

Simple mediaplayer play mp3 from file path?

痴心易碎 提交于 2019-12-17 06:12:02
问题 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(); 回答1: 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

error opening trace file: No such file or directory (2)

扶醉桌前 提交于 2019-12-16 22:46:11
问题 I am getting the above error: error opening trace file: No such file or directory (2) when I run my android application on the emulator. Can someone tell me what could be the possible reason for this? I am using android-sdk-20 and below lines are added to AndroidManifest.xml <uses-sdk android:minSdkVersion="14" android:targetSdkVersion="15" /> I have also added the line: <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> since I thought that there may be some issue

Android 6.0 Marshmallow. Cannot write to SD Card

我的梦境 提交于 2019-12-16 22:23:52
问题 I have an app that uses external storage to store photographs. As required, in its manifest, the following permissions are requested <uses-permission android:name="android.permission.CAMERA" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> and it uses the following to retrieve the required directory File sdDir = Environment .getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES); SimpleDateFormat dateFormat = new SimpleDateFormat("MM-dd", Locale.US);

ENOENT (No such file or directory) when trying to open a file downloaded from URL with AsyncTask

杀马特。学长 韩版系。学妹 提交于 2019-12-14 02:23:44
问题 I download a file from URL with AsyncTask. The file is saved and I can see it on my sdcard. In my app I want to open this file after it is downloaded but there is following error: java.io.FileNotFoundException: /mnt/sdcard/XML/zurt.xml: open failed: ENOENT (No such file or directory) Do I have to wait a specified time between downloading and opening the file? What is the problem? I have these both permissions: <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" > </uses

Read/Write Removable SD Card (android emulator)

与世无争的帅哥 提交于 2019-12-14 02:20:25
问题 Every time I try to read the informations of SD Card (removable storage), I get android.system.ErrnoException: statvfs failed: EACCES (Permission denied) I added permissions in manifest file : <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> As minSdkVersion > 23 public static void verifyStoragePermissions(Activity activity) { // Check if we have write permission int permission =

Can not locate the sdcard file(not hard code) in android 6.0

不打扰是莪最后的温柔 提交于 2019-12-13 23:41:58
问题 Since android 6.0, the sdcard path is no longer "/storage/sdcard1/", "/storage/sdcard-ext/" or something. The path depends on the phone instead. If I use Nexus 5x AVD, the path is "/storage/1D15-3A1B/". When I use Nexus 6p AVD, the path is "/storage/4679-1802/". So how can I dynamically write the sdcard path in program to locate the file in external sdcard? Thank you! 回答1: Have a look at getExternalFilesDirs() . 回答2: It seems that I found the solution. I'm using the access storage framework.