Questions tagged [android-file]

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

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

Use this tag if you have reason to believe your usage of files under Android causes the error your question is referring to.

1038 questions
9
votes
0 answers

FileUriExposedException when showing notification with sound

Users of my app can select the ringtone that should be played when they receive a notification within my app. I show a ringtone selection dialog: Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER); …
fweigl
  • 21,278
  • 20
  • 114
  • 205
9
votes
1 answer

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 these two folders the fact that Android may…
KaliMa
  • 1,970
  • 6
  • 26
  • 51
9
votes
3 answers

getExternalFilesdir Fail

OnActivityCreated I'm doing: activity.getExternalFilesDir(Environment.DIRECTORY_PICTURES); In logcat I get: com.package W/ContextImpl﹕ Failed to ensure directory: /storage/sdcard1/Android/data/com.package/files/Pictures This happens only on…
Jumpa
  • 4,319
  • 11
  • 52
  • 100
9
votes
2 answers

Android: Failed to ensure directory when getExternalFilesDir(null)

As shown in the title, when I called the method getExternalFilesDir(null), i got a warning like this: Failed to ensure directory: /storage/emulated/0/Android/data/com.xxxx.app/files So, it turns out that the i cannot get the path…
Jerome
  • 1,749
  • 1
  • 14
  • 40
9
votes
2 answers

How to capture/record clip from Video URL in Android and save to phone

In Android, is it possible to record a short clip (ex: an arbitrary 5-10 seconds in the video) from a Video URL (ex: http://www.test.com/video.mp4)? For example, I'd like to stream a video (from url) in an Activity and allow the ability to…
code
  • 5,294
  • 16
  • 62
  • 113
9
votes
4 answers

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; BufferedInputStream buffInputStream; …
Arundas K V
  • 801
  • 2
  • 14
  • 28
9
votes
3 answers

Android: Too many open files error

I have the following operation which runs every 3 seconds. Basically it downloads a file from a server and save it into a local file every 3 seconds. The following code does the job for a while. public class DownloadTask extends AsyncTask
Lazy Ninja
  • 22,342
  • 9
  • 83
  • 103
9
votes
6 answers

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 new directory if it does not exists or returns me…
Anshul
  • 7,914
  • 12
  • 42
  • 65
8
votes
4 answers

How to create folder (Android R - Api 30)?

Read that Android 11 has scoped storage, but I can't find any information, how can I create and use folder in /storage/emulated/0/ ? Old methods works only on api 29 and below :(
Fedor Sedov
  • 101
  • 1
  • 1
  • 8
8
votes
1 answer

Gmail error "Unable to attach file"

I am trying to email PDF file using Gmail. However, Gmail app is showing toast: Unable to attach file PDF file is not-corrupt and is generated successfully in application's cache directory. Code: (Please comment below if you need code in Java.): …
8
votes
1 answer

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.getExternalStorageDirectory(),…
SAYE
  • 1,247
  • 2
  • 20
  • 47
8
votes
4 answers

Is it possible to get a regular File from DocumentFile?

For Android, the following code returns a Uri that can be used to create DocumentFile corresponding to a directory. Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE); startActivityForResult(intent, REQUEST_CODE_CUSTOM_FOLDER); Since many…
Hong
  • 17,643
  • 21
  • 81
  • 142
8
votes
3 answers

Encrypt Existing Database with SQLCipher in Android

I have a database file in my assets that I copy in the app database folder. After the copy (it works), I want to encrypt the copied database with SQLCipher. For some reason, I get this error: Database: sqlite returned: error code = 26, msg =…
Mr.Sparkle
  • 173
  • 1
  • 9
8
votes
2 answers

CreateTempFile returns No Such File or Directory in Pictures folder?

So here is my code: String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); String imageFileName = "JPEG_" + timeStamp + "_"; File storageDir =…
Rendy
  • 5,572
  • 15
  • 52
  • 95
8
votes
1 answer

Picture file captured with camera intent empty for a while in onActivityResult

I am having a very strange bug trying to take a picture via intent. Activity code (a little simplified): private void startCapture() throws IOException { // Create output file final File photoFile = makePhotoFile(); _photoPath =…