Android getExternalCacheDir() exact location - android

I am using below method to save one image file in the cache of my app.
File path=getActivity().getExternalCacheDir();
In my log i am getting that my image is saved in my internal storage of my phone
/storage/emulated/0/Android/data/me.XXX.xxx/cacheimagefile100.png and i can access that image file for sharing to other apps using intents. But some of the users using my app getting error in this line of code like
Attempt to invoke virtual method 'java.io.File android.app.Activity.getExternalCacheDir()' on a null object
I dont know why it is getting. Even my app is a using internal storage (OS VERSION Android 7) not the external SD Card storage cache.
Can anyone tell me what is the reason behind that?
What is the good fix for this?
I used getCacheDir() method. But when i am sharing the file through intent(Basically it is image) the image is empty and null. Tell me a fix for this.

Related

not an error (code 0) in my Moto G4 .

not an error(code 0) cannot open database in read/write mode. I am getting this error in my phone. I have mounted my SD card as internal storage and after few days I got this error. I am not able to download any images,music,etc. anything from any Application. It says storage is full even when it's not. Please help me.
Maybe your database doesn't exists yet or you have to create a new one. Check if you did the following correctly:
Used SQLiteOpenHelper#getWritableDatabase Reference.
External storage currently mounted or not. Reference.
The path you provided is correct?

Android studio internal file path, file not saved

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.

Android File on Internal Storage not found

I'm trying to write a file in my app's android internal storage space. After so many trials, I was finally successful using this method Writing/Reading Files to/from Android phone's internal memory . However, when I go to data/data/package_name/files, I cannot find my package, and cannot even find the MyFile.txt. In fact, I can't find them anywhere in internal memory. Why is that?

SQLite Database in external sdcar

i am newbie to android .
.
I have problem that how to get external storage directory.In my device it is storage/sdcard1 path.
but it is also not working.
How can I set external storage directory path to db ?
PLease help.
Any answer will be appreciated.
Before answering this question I want you know something about the android framework..
Android contains default sqlite handling options which saves database file in internal storage directory
It is good practice to use it..
But still if you want to save in custom directory follow these instructions
By default android partitions the internal storage into a partition called SD card
which can be accessed by calling frameworks Function
File Environment.getExternalStorageDirectory()
But on some devices there is an option have external memory card
If that is your case you can do that by calling java function like this
new File("/mnt/sdcard1/");

Is it possible to create shared preference files in sdcard

Can anyone help me ? Is it possible to create shared preference files in sdcard rather than on private path of an android application.
You cannot modify where shared preferences are stored.Its a private storage. if you want to use sd card use
Environment.getExternalStorageDirectory(). and get the path of directories stored in sdcard.
it is possible by reading&writing the xml file into the external storage ,but it's not the same as sharedPreferences. you will have to implement your own way , or use the android code of this class.
however , there are some disadvantage over using the internal storage:
anything you store on the sdcard is visible to every application and the end user can read it by just opening it.
only in the internal storage you get some sort of protection against reading the file , so that only rooted devices can read the files.
external storage can also be unmounted , so the data can sometimes be unreachable. you need to handle possible errors that can occur because of this.
uninstalling the app while the sd card is mounted means that the data will stay on the sdcard .

Categories

Resources