I have some problems accessing local files on my Android Application. I use FileInputStreamclass to access to a file on the SD card without any problems.
The issue appears when I close my application and add a new file to the SD Card manually. When I try to access this new one on my application it is not accessible (not found).
I think it has to be related to the cache that Android manage for every application.
I would like to clean this cache when my application is closed. Maybe it is due to the fact that when I close the application. (the activity) it is stopped but not closed, and the cacheis not cleaned.
Anyone has this trouble? Any ideas?
problem solved. On SD Card was due to a bad coding. Refreshing the SD files was done on OnCreate method in the Activity and was not executed altough the activity was closed. I've changed to OnStart and works fine.
And regarding the access to remote files on a servers I've used URLConnection.setUseCaches(false) and now is working fine too!
Thanks
Related
I'm developing application that is targeted for API 18. Application download data by Bluetooth and GSM and stores data on internal sdcard (usually \emulated\sdcard - readed by Environment.getExternalStorageDirectory()).
Till this time everything works fine - files and folders are correctly saved.
Today i've faced very strange behaviour:
1) Started the app, and it works for over an hour and store data files.
2) After that, i've closed app and want to download data to the computer.
Before plugin USB, I've used Android file explorer software to check stored data.
I was shocked - new folder (any new data) was gone!
It's like system removes or hide all files and data created in last app session.
Remarks: application don't have procedures for deletion folder or files. Also it works good on previous versions of Android (mostly 4.X and 5.X).
It's very strange because app has warning mechanism when save isn't possible and that warnings wasn't displayed. So I think, write was allowed by system, but data isn't visible at this moment.
Another stranger thing is that application can't write any file in internal storage from this moment (and the warnings are displayed as should in this case).
It looks like Android Marshmallow "decides" in particular moment - your new data won't be available anymore, and your app won't write to internal card.
I've checked app permissions in system - OK.
Any ideas, why this happens? How to deal with it?
You may refer to these guides for managing permissions during runtime: http://www.howtogeek.com/230683/how-to-manage-app-permissions-on-android-6.0/
https://developer.android.com/training/permissions/requesting.html
I've seen multiple instances where people claim that updating an Android app does not remove its internal files. However, I'm reading and creating a file using openFileInput() and openFileOutput() respectively, which works fine, until the app is updated where apparently the file can not be read, or is deleted.
As I'm developing a game, I would like to avoid SharedPreferences.
As saving progress is more or less mandatory, would writing to an external location be a better alternative? The user shouldn't although be able to tamper with the file (its a serialisation).
Otherwise, is there a way to keep the internal file after updating? Thanks
Why do you not use an SQLite database for this purpose. Updating the app will leave the database untouched unless you explicitely instruct your app to change or delete it.
I've use the Android method Context.getExternalFilesDir() and save some data from my app on a external file. So far, when I uninstall the app on an Android 4.4, this external files are being erased as well, but this is not the case for Android 2.3.
I was wondering if this is possible and if so, how would I achieve this kind of behavior in Android 2.3.
Regards
Jose
4.4 changed the behavior for the SD card. Prior to that, data on the SD card had no protections, any app could read or write anywhere. Afterwards, files and directories were protected so only the app that created them could read or write them. Because 2.3 doesn't track who owns the files, it can't delete them when uninstalling. The closest thing you could do is delete the files yourself on a regular basis.
I'm interested in the analytics of how many users have moved my application to the SD card. Is there a way to determine this data? Ideally, I'd want to log an event that its been moved to the SD card (and vice-versa), but at this process is out with the application, I'm unsure how to go about getting what I want. For what its worth, I'm currently using Flurry for analytics. Thanks!
Check the path of your application files when the application is started. Edit: I was thinking of checking the running executable path, however that doesn't seem to work.
Have you tried the answer to How to detect when an App is force moved to SD-Card on rooted Android ?
I have an app that saves files to the sd card but apparently some people that use the app don't see the file until they restart their phone. How can I fix this?
I've seen similar scenarios where files are not visible until application is closed. May be your users may "force close" the application just to be sure is an issue with your application.
My guess is that you may be are not closing the OutputStream object you use to write the files on the SD card, I mean, call out.close() method, where out is an instance of OutputStream.