Questions tagged [android-file]

Specifically the Android `File` class, but may also refer to the generic concept of files under the Android operating system

android-file
Filter by
Sorted by
Tagged with
923 votes
23 answers
633k views

android.os.FileUriExposedException: file:///storage/emulated/0/test.txt exposed beyond app through Intent.getData()

The app is crashing when I'm trying to open a file. It works below Android Nougat, but on Android Nougat it crashes. It only crashes when I try to open a file from the SD card, not from the system ...
Thomas Vos's user avatar
  • 12.4k
348 votes
15 answers
592k views

Show Image View from file path?

I need to show an image by using the file name only, not from the resource id. ImageView imgView = new ImageView(this); imgView.setBackgroundResource(R.drawable.img1); I have the image img1 in the ...
Alex's user avatar
  • 16.5k
194 votes
13 answers
275k views

How to create directory automatically on SD card

I'm trying to save my file to the following location FileOutputStream fos = new FileOutputStream("/sdcard/Wallpaper/"+fileName); but I'm getting the exception java.io.FileNotFoundException However, ...
Kshitij Aggarwal's user avatar
145 votes
3 answers
171k views

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

Can anyone tell me the difference between these two methods: file.mkdir() file.mkdirs()
Krishna Kankal's user avatar
67 votes
8 answers
146k views

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

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 "...
Drew's user avatar
  • 13k
65 votes
4 answers
69k views

File.createTempFile() vs. new File()

In order to save a picture on the SD card, I currently use the function File.createTempFile: File imageFile = File.createTempFile(imageFileName, MyApplication.JPEG_FILE_SUFFIX, MyApplication....
Yoann Hercouet's user avatar
61 votes
5 answers
36k views

Database won't remove when uninstall the Android Application

I have two major questions. Database won't delete when uninstall app. Downloaded files won't delete while unstable the app. There is a database in my android application. I create it by java class ...
KZoNE's user avatar
  • 1,279
60 votes
9 answers
107k views

Where are Android Emulator Images Stored?

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. ...
Get Off My Lawn's user avatar
54 votes
3 answers
76k views

List all the files from all the folders in a single list

I am looking for the solution to list all the files from root/Android device. Suppose there are three folders inside the root directory, but I want to display all the files in all of these folders in ...
Kanika's user avatar
  • 10.7k
51 votes
8 answers
107k views

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

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....
Skizo-ozᴉʞS ツ's user avatar
47 votes
16 answers
53k views

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

I'm driven crazy with this: Log.d("STATE", Environment.getExternalStorageState()); File f = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM), "work_data"); Log.d("...
MHM's user avatar
  • 854
47 votes
6 answers
125k views

Save bitmap to file function

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); ...
Oliver Dixon's user avatar
  • 7,171
46 votes
4 answers
85k views

Load a file from external storage to Inputstream

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 ...
Talha Malik's user avatar
  • 1,529
46 votes
16 answers
517k views

How to access /storage/emulated/0/

I have written a code to record audio and save it to below file location. private String getFilename() { String filepath = Environment.getExternalStorageDirectory().getPath(); File file = new ...
nerdy_me's user avatar
  • 471
45 votes
5 answers
52k views

Create and Share a File from Internal Storage

My goal is to create a XML file on internal storage and then send it through the share Intent. I'm able to create a XML file using this code FileOutputStream outputStream = context.openFileOutput(...
Kirk's user avatar
  • 16.2k
40 votes
7 answers
138k views

Simple mediaplayer play mp3 from file path?

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 is my code: private MediaPlayer mpintro; . . ...
John simit's user avatar
  • 1,305
31 votes
7 answers
56k views

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

I need the name (String) of all files in res/raw/ directory. I tried: File f = new File("/"); String[] someFiles = f.list(); It looks like the root directory is the root of the android ...
jasonsemko's user avatar
29 votes
4 answers
35k views

Android - How to get selected file name from the document

I am launching the intent for selecting documnets using following code. private void showFileChooser() { Intent intent = new Intent(Intent.ACTION_GET_CONTENT); intent.setType("*/*"); ...
AndroidDev's user avatar
  • 1,201
25 votes
11 answers
72k views

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

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 ...
Lazy Ninja's user avatar
  • 22.5k
24 votes
6 answers
65k views

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

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 ...
aman.nepid's user avatar
  • 2,954
22 votes
6 answers
52k views

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

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("...
Prashant Kadam's user avatar
20 votes
4 answers
38k views

Copy files from a folder of SD card into another folder of SD card

Is it possible to copy a folder present in sdcard to another folder present the same sdcard programmatically ?? If so, how to do that?
Siva Kumar's user avatar
20 votes
8 answers
71k views

How to get the internal and external sdcard path in android

Most of the new android devices have an internal sdcard and an external sdcard. I want to make a file explorer app but I can't find out how to get the path to use in my app because File file = ...
Mahmoud Jorban's user avatar
19 votes
6 answers
28k views

Using Dropbox API to upload a file with Android

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 ...
Dominik's user avatar
  • 1,695
19 votes
4 answers
16k views

how to create a file with world readable permission under subdirectory of files directory

I need to create files under myapp/files/subdir with global permission in my application. I do this because I use external applications to open some files Using this FileOutputStream fos = ...
ikbal's user avatar
  • 1,864
16 votes
11 answers
42k views

Missing android.support.FILE_PROVIDER_PATHS meta-data

I am trying to open the pdf file which I downloaded & saved in external storage. But When I open my app its gets crashed and showing following error; 08-31 00:58:31.304 1807-1807/? E/...
priyanka kamthe's user avatar
16 votes
2 answers
1k views

Android 5(HTC) EACCES (Permission denied)

app can't create folder/file on android 5(HTC HTC6525LVW os version: 5.0.1) external storage in directory owned by app. Parent folder is returned by [getExternalFilesDirs(String type)][1] method. ...
Martin Vandzura's user avatar
16 votes
2 answers
9k views

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

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 ...
michael's user avatar
  • 3,905
15 votes
3 answers
17k views

Downloaded files get deleted automatically

In my app, there are a few files that users can download. The files get downloaded via the android download manager. But, since a few weeks now, hundreds of users have been complaining that their ...
Sagar's user avatar
  • 3,186
15 votes
4 answers
35k views

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

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/<package_name> on the internal ...
superuser's user avatar
  • 635
15 votes
1 answer
14k views

Allow User To Select Path For Save File in Android

I am developing one application for our client and there is one little functionality where we are stuck, so need your help, Scenarion: We have developed one recycle view, from where users can see ...
Vickyexpert's user avatar
  • 3,157
14 votes
2 answers
6k views

Android File Provider Illegal Argument Exception

I am using file provider to save photo to a given destination. I get: java.lang.IllegalArgumentException: Missing android.support.FILE_PROVIDER_PATHS meta-data while trying to open activity to ...
Michał's user avatar
  • 655
14 votes
4 answers
18k views

Why does FileOutputStream throw FileNotFoundException?

The Android Developer reference (this page) says: Throws FileNotFoundException But at the very start, it says: Open a private file associated with this Context's application package for writing. ...
1owk3y's user avatar
  • 1,183
14 votes
2 answers
11k views

Convert a file (<100Mo) in Base64 on Android

I am trying to convert a file from the sdcard to Base64 but it seems the file is too big and i get an OutOfMemoryError. Here is my code : InputStream inputStream = null;//You can get an inputStream ...
Labe's user avatar
  • 1,272
12 votes
3 answers
21k views

Android select mp3 file

Sorry if this has already been answered, but I can't specify my question very well. I have an activity that needs a song file from your device, and I want it when I press a button to open a dialog to ...
Sartheris Stormhammer's user avatar
12 votes
3 answers
28k views

Android, how to choose save file location?

is there any solution how to choose the saving files location? maybe with the original file browser, to choose the destination? thank you!
David's user avatar
  • 1,752
12 votes
4 answers
22k views

How can I delete file on Android 11 (API 30) without system confirmation dialog?

I have an app which records videos to shared MOVIES folder. I can delete those files on Android 11 (API 30) with contentResolver.delete(uri, null, null) method in my recorded videos activity. But if I ...
user25's user avatar
  • 3,047
12 votes
1 answer
547 views

Questions about using Android Backup Service with a SQLite database

My app stores all user data and preferences in a SQLite database, which I'd like to persist if the user gets a new phone, reinstalls, or does a factory reset. I've done some reading in Android's Data ...
NSouth's user avatar
  • 5,197
11 votes
1 answer
20k views

How to Get Absolute Path in Android for File?

btnimport.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent fileintent = new Intent(Intent.ACTION_GET_CONTENT); fileintent.setType("*/*"); ...
Vihang Patel's user avatar
11 votes
3 answers
17k views

add image to twitter share intent android

I'm trying to add an image to my twitter share intent. I save an image locally in one class and then in another I get the image and try to attach to my intent. Here is my code private void ...
Hugo Boss's user avatar
  • 213
11 votes
2 answers
2k views

How do I let a user upload files to internal storage?

I am writing a small app that reads files that must be regularly written to storage on the device from a source external to the device, be it USB, Bluetooth, Airdroid, etc. From what I've read, ...
ProfK's user avatar
  • 50.1k
11 votes
0 answers
11k views

Open folder content with default file manager in android

I am working with pdf files in my android app. In a Alert Dialog pressing "Yes" should open the pdf file location in default file manager app. I tried with this but it always open a chooser. Even-...
Karthikeyan Ve's user avatar
10 votes
5 answers
40k views

Writing Text File to SD Card fails

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 ...
Paul's user avatar
  • 1,734
10 votes
4 answers
41k views

Read/write file to internal private storage

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: ...
STeN's user avatar
  • 6,260
10 votes
1 answer
13k views

How to share *.txt file in android

I tried many ways but I can't do this. I have a *.txt file. I want to share it via Bluetooth, wifi, email and .... When i used this code i cant share the file: File file = new File(Environment....
sam nikzad's user avatar
  • 1,317
10 votes
1 answer
10k views

Why do I need the WRITE_EXTERNAL_STORAGE permission with getExternalCacheDir() on Android Lollipop?

My app writes (and reads) cache files to the getExternalCacheDir() location. Before Android Lollipop (API 21) I've been using this permission with success: <uses-permission android:name="android....
murrayc's user avatar
  • 2,113
10 votes
1 answer
3k views

getFilesDir() vs getCacheDir()

In Android you can use getFilesDir() to get a path to your internal /files/ folder, whereas getCacheDir() gets you a path to your internal /cache/ folder. Is the only functional difference between ...
KaliMa's user avatar
  • 2,000
9 votes
4 answers
10k views

file.delete() from android internal storage return false

I have a method to download a image from url and save it in a folder at Internal storage public void saveDynamicImage(String url,String fileName, String folderName) { InputStream iStream; ...
Arundas K V's user avatar
9 votes
6 answers
25k views

Android How do I check the number of files in a directory

I am creating a directory in internal memory of device for storing files for application use.I am using: File dir = context.getDir(userfavorites, Context.MODE_PRIVATE); The above code will create a ...
Anshul's user avatar
  • 7,944
9 votes
3 answers
11k views

Android: how to get list of all preference xml's for my app and read them?

how to get list of all application preferences for application, 1. I am saving shared preference in this manner 2. I know that they are in data/data/app_packagename/shared_prefs 3. THE PROBLEM: ...
Akhil Jain's user avatar
  • 14.1k

1
2 3 4 5
22