Android studio internal file path, file not saved - android

Small problem, I am trying to save my PDF file in phone (LG G5 - no SD card), but file is never saved, is there a problem with file path? Using PdfBox-Android library. See picture from debugger - Debugger picture. The aim is to save pdf file to internal downloads folder. I tried 10x solutions, nothing is working. Please help.

The aim is to save pdf file to internal downloads folder
Use Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), not getFilesDir(). Also:
You will need the WRITE_EXTERNAL_STORAGE permission
You will need to handle runtime permissions
You will need to get the file indexed by the MediaStore before it will show up

I think you are trying to run the code on M version. Please check for Write External Storage permission and other read and write permissions in manifest file. For Android M and above versions use the concept of runtime permissions.
Let, me know if it was helpful.

Related

Access files stored in the shared storage on Android

I copy a file from USB to my SamSung S7 tablet using My Files app shipped with my tablet. I can find this file under /data using My Files app.
I believe this file is stored in the shared external storage. As pointed in
https://developer.android.com/training/data-storage
I need Android Storage Access Framework to access this file.
I want to access this file with my own app and I need to know the URL. What's the URL look like?
Thanks.
YL
A file URL looks like this in Android and you can use this type of URL to access files:
file:///path/to/foo.txt
file:// is used to refer to URL pointing to a world-readable file.
You can get path to directory from one of these getExternalFilesDir() or getExternalCacheDir() or getExternalMediaDirs(). Hence, getExternalStorageDirectory is deprecated and no longer recommended for use. (Read more here)
Lastly, make sure you have made permission to access: WRITE_EXTERNAL_STORAGE and READ_EXTERNAL_STORAGE
Let me know if you have any questions. Thanks.

Android Accessing get external directory

Now, I am working on data transmission using bluetooth. I have such problem in selecting file in SD card/ internal storage.
I am already put permission in manifest :
I am using this command to get access the file
File sdCard = Environment.getExternalStorageDirectory();
But when I am check using this command if (sdCard.canRead()) , it can't read the path.
Anyone have the solution within my problem? Thanks anyway
The Android Dev resources has a good guide on this.
Assuming you have all the correct permissions, you could be facing issues where the storage is not mounted or there is not enough space. The guide explains how to check the state of the External Storage Dir, etc.
Did you add the following line to the AndroidManifest?
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
From android SDK version 4, you need to add that line to access external storage by your app.
Some of other issues are, (Check whether phone detects the SD card)
SD Card is Not Clean
Battery Voltage
Card Slot is Squeezed
Metal Wires in the Card Slot Get Rusty and Twisted
Malware Invade SD Card
SD Card is not Formatted Properly
SD Card is Broken
The Phone Breakdown
problem solved.
The problem is related with new android SDK. We need to add additional permission.
Thanks everyone.

How to transfer txt data file from Android app to Windows

I have an Android application that generates some data (simple text file) that I would like to transfer to my PC for further processing. My understanding is that my storage options for a place to save such a file are a) internal storage or b) external storage. My device is a rooted Nexus 7 running Marshmallow, and I can't get either option to work.
With internal storage I'm able to write the file but then it's nowhere to be found using ADB or Eclipse DDMS. With external storage I'm getting FileNotFoundExceptions which I'm guessing are due to new complicated permissions, so none of Android saving file to external storage is working.
Is this possible and, if so, is there an easy way to do it?
What is your targetSdkVersion? If you target 22 and below, the new permission policy won't take effect.
It is possible to write a text file in Android and read the same in your PC using external-storage.
This app does the same.
You can find a simple example here.
If this does not work for you, kindly share your code-snippet that writes the file.

Giving FFmpeg access to my app's data directory?

I'm working with one of the many Android FFmpeg libraries on GitHub, which each involve an NDK wrapper around a C binary. I'm trying to give other apps access to the video file I have edited with FFmpeg (and saved in External Storage), but at least on Android 6.0, the new permissions system prevents them from being able to access the shared file unless they themselves have the External Storage permission granted. The solution here would be to use content providers to open up a directory for other apps to access. However...
My FFmpeg binary is contained within the app's data directory, but it fails when I try to access or modify a video file saved there. As mentioned above, it has no problem accessing external storage.
Is there a way to give FFmpeg access to my app's data directory, giving it read and write permissions? Would naming the library with the same package name do the trick?
Any ideas? Thanks for any advice!

How to Play Video in Android in Videoview or WebView from Internal Storage

Hi all and thanks in advance.
After all day trying and searching why videos load in a html with a webview or directly the .mp4 with a VideoView, i have discovered whats the problem.
Apparently files in internal storage just have app permisions, but MediaPlayer or other externals objects does not have permissions. Is this rigth?. If i put that same video in res/raw it can be played with no problem.
Ok. I need my files in internal storage, and i get the files from a internet .zip wich i unzip under a location WITH path separators, because is a whole structure.
So i have been looking and trying but i cannot find how to do it, because if i try to give permissions to a file, if my device, and it is not, rooted, i just found that just can do a context.openFileOutput(filePath, Context.MODE_WORLD_READABLE) but this give me a exception because there is path separators, what i cannot understand whats the problem with that....the thing is that i cannot try that when i unzip the file neither in other future moment cause the path separators.....how can i set global permissions to an internal file with path separators?
Or what can i do? the thing is i need to make a webview load a html with all pictures and videos in same folder with path separators.....it is impossible in internal storage?
Really thanks for all, any help will be appreciated..
I was running into the exact same issue. It was particularly troublesome because I had no similar issues with viewing images in an ImageView from internal storage.
Two ways to go about it, depending on your app's requirements:
Content Providers
Temporary File in External Storage
This worked for me the best and easiest. I simply copied the video file to external storage (it was small enough and not so sensitive if it got abandoned in external storage), played it and when I was done playing it (activity ends) I deleted the external file. Easy peezie.
I would use external storage and add the read permission to the manifest before application:
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"></uses-permission>
<application

Categories

Resources