android-external-storage

Android - API 23 Unable to get USB/SD Card Directory

大憨熊 提交于 2019-12-12 03:53:09
问题 I used to get all the files in USB/SD Card from "/storage/external_storage" like so File = new File("/storage/external_storage"); file.listFiles() and show the files and folders in my own Fragment and it worked great until API 23. Where now I am unable to get the file list from the path. I know in Android Marshmallow (23) there were permission changes and some USB Connection behavior changes. If your app supports user interactions with the device over a USB port, take into consideration that

IllegalArgumentException while reading a video file from External Stroage

浪子不回头ぞ 提交于 2019-12-12 02:17:44
问题 I have a problem that I am getting IllegalArgumentException while reading a video file from sdcard. I don't know why? Please suggest me the right solution for the same. ErrorStack: 11-03 18:56:18.733: ERROR/AndroidRuntime(24192): FATAL EXCEPTION: main 11-03 18:56:18.733: ERROR/AndroidRuntime(24192): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example/com.example.TestCryptoActivity}: java.lang.IllegalArgumentException: File /mnt/sdcard/E0022505.mp4 contains a path

Save image on external Storage

坚强是说给别人听的谎言 提交于 2019-12-11 07:57:34
问题 Hey I want to save an image in the external storage. I got two versions out of here but both aren't working. Goal is that the user clicks a button and the image is saved and then the user can also see it in the gallery. So here is Version one: String path = Environment.getExternalStorageDirectory().getPath(); File outputDir= new File(path); outputDir.mkdirs(); File newFile = new File(path+"/"+"test.png"); FileOutputStream out = null; try { out = new FileOutputStream(newFile); mutableBitmap

Can't ACTION_VIEW a file on external storage

血红的双手。 提交于 2019-12-11 03:21:26
问题 I have a file in my Android phone's external storage (emulated, in this case). Knowing the path to it and / or having a File object representing it, how can I use an Intent to open it in the appropriate app? The first thing I tried was: startActivity(new Intent(Intent.ACTION_VIEW, Uri.fromFile(file))); I'm sure this was working at one point, because I tested it and moved on to another part of the app. Now it always throws ActivityNotFoundException . The file definitely exists because file

Unable to create folder inside Android/data

痞子三分冷 提交于 2019-12-11 01:07:00
问题 I'm facing a problem with creation of folder inside Android/data folder. My code need to create folder, and copy a file from asset folder inside it. This is my code: private File getFileForShare(String filename) { try { String extStorageDirectory = Environment.getExternalStorageDirectory().toString(); File folder = new File(extStorageDirectory, "/Android/data/" + context.getPackageName()); if (!folder.exists()) { folder.mkdir(); } AssetManager am = context.getAssets(); InputStream inputStream

Can't open external storage file in Android N using FileProvider

寵の児 提交于 2019-12-10 19:36:34
问题 I am having trouble opening file inside external storage with Android N. File path file:///storage/emulated/0/Download/SamplePDFFile_5mb.pdf Initial implementation Perfectly work on Android version lower than 7 File file = new File (Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), "SamplePDFFile_5mb.pdf"); Uri uri = Uri.fromFile(file); Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(uri, "application/pdf"); startActivity(intent); The same

Android Oreo (API 26) - Create dir in external storage

回眸只為那壹抹淺笑 提交于 2019-12-10 13:16:09
问题 I've been developing an app on nougat that creates a directory in the external storage. I used to do it like this: final File dir = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/Chords/Processed Audio"); dir.mkdirs(); This code does not seem to work on API 26 (Android Oreo). The directory is not created. How can I achieve the same thing, preferably that works on all android version from API 21 to API 26? 回答1: I have no problems running your existing code on a Nexus

How to use AccessController in android?

别说谁变了你拦得住时间么 提交于 2019-12-10 11:36:53
问题 In an Android application (API level 10),I do not use below permission in manifest : <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> So application would not write on root of external storage.But when I try to check read/write permission via AccessController by this code: File f = Environment.getExternalStorageDirectory(); String path = f.getAbsolutePath(); String actions = "read,write"; try { AccessController.checkPermission(new FilePermission(path, actions));

Does Environment.getExternalStorageDirectory() returns a usable data folder when no sd card is mounted?

£可爱£侵袭症+ 提交于 2019-12-09 16:18:11
问题 Imagine an Android device with no sd memory insterted. Only its own internal memory. I'm not sure what Environment.getExternalStorageDirectory() returns in this case. Null or a internal memory location valid for permanent data storage? 回答1: public static File getExternalStorageDirectory() Added in API level 1 Gets the Android external storage directory. This directory may not currently be accessible if it has been mounted by the user on their computer, has been removed from the device, or

java.io.FileNotFoundException: No such file or directory Error

不想你离开。 提交于 2019-12-08 13:02:01
问题 I am downloading images to smartphone. For older versions not problem my code is working but for Oreo it is not working. I tried this code in Emulator. I implemented a function to save image to external storage. private void saveImageToExternalStorage(Bitmap finalBitmap,String name) { String root = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).toString(); File myDir = new File(root + "/xx"); myDir.mkdirs(); String fname = name + ".jpg"; File file = new File