-
Notifications
You must be signed in to change notification settings - Fork 120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Method getExternalStorageDirectory is deprecated (could effect the external viewer calls) #130
Comments
The problem is that the introduction of Scoped Storage is making a Mess for apps that implement the Intent.ACTION_VIEW with shared folders. The Android Apps currently have 2 ways to pass the Uri to an intent: the old method is The problem arises because some Apps follow the old approach (like GPX Viewer): when the Uri points to a shared Folder (like the ExternalStorageDirectory and sub folders), the app opens the specified file; when the Uri is from a FileProvider, the app make a copy of the file into its own folder and opens it from here (in order to avoid any permission loss). In this case, if we use the FileProvider method, the app will make a new copy of the file every time it opens it. Currently we implemented both approaches to pass the KML/GPX Files to Intent.ACTION_VIEW, but we are still using the old one by default. We use the new one only for Earth, that refuses to open files with the old method. We set the use of Content Provider for Earth here: GPSLogger/app/src/main/java/eu/basicairdata/graziano/gpslogger/ExternalViewerChecker.java Line 156 in c022c32
You could enable it for your app (for testing purpose) by adding the following line to GPS Logger's exceptions: if (a.PackageName.equals("YOUR_APP_PACKAGE")) a.requiresFileProvider = true; We have in plan to enable the new method by Default (it could be enabled on the next App's Update), but we must first test the behaviour with all the apps we know are working as GPX/KML Viewer.
In the future, when Google will force to update the API level to 30+, we will have to remove all the usages of the legacy APIs (like getExternalStorageDirectory) from GPS Logger in favour of new ones. But for now we are waiting a clearer guidelines. |
Dear @GrazianoCapelli Thank you very much for the really detailed answer. I've learned a lot reading your comment. I already thought that all of this stuff is not so easy to handle because Google repeatedly throws all (former) file handling overboard (it seems that everything is deprecated in the Android world :-) :-( ) My app was initially file-based, after I had struggled through the Google Docs, I then switched the internal file handling completely to 'Uri based' handling because the file handling no longer worked well under some current Android versions (filename to uri conversion and vice versa is always a topic at stackoverflow.com). I cached files beforehand in order to get access rights and to be able to open them in my app (as you described). Now most of this special handling is no more needed, but I still can't really make out all of Google's new guidelines. It took me several days of trying out and put together the right intent filters for my app and the underlaying file handling. Now everything seems to work relatively fine and after I have included 'requestLegacyExternalStorage = "true"' in the manifest, I can easily integrate my app as a viewer in GPS logger on Xiaomi's phones running under Android 10 too. My conclusion: I've been in the professional software development for more than 25 years now (but no Android till now) and I've never stumbled upon so many deprecated traps as I do with Android. I only do Android programming on a hobby basis, the much free time in the Corona crisis practically drove me to do it and I'm certainly still an Android beginner when it comes to programming, but in general regarding programming I think I'm a little bit skilled due of my daily work . But that doesn't help you with Android that much, because you always have to go back to start :-) Studying Android developer docs seems to be a life's work (writing Android programming guides too) :) Thanks for sharing GPS Logger with us, it's really a great app! Regards Ralph
} |
Dear @WRPSoft I found a WRPElevationChart on the Play Store: Hoping I'm not wrong, I assume you are speaking of it. We are happy to be aware of a free and compatible Track Viewer on the Play Store. I haven't found any reference to License and any Issue Tracker, so I am writing to you here to report a small issue I faced with WRPElevationChart: It seems that the method that opens the Track runs independently from the permission.
Please consider that the consideration I written here above is made without browsing your code, and could be wrong. |
Dear @GrazianoCapelli, Maybe I should have asked before referring to GPS Logger, but I've been a little pressed for time the past few days and really enjoy using GPS Logger. So I really wanted to refer to GPS logger app. But I am glad that you are okay with that. By the way, this is my first real Android app. Professionally, I work in desktop development and as said before, there are really many traps in the Android development world. Thanks for the bug report and the nice words. Indeed there are still a few passages that I should revise a little more. In fact, when accessing files, I would have to consider the RequestPermissionsResult (at least when handling the intent). But all this permission management with regard to file handling is not so easy to do under Android, especially now that Google is again fundamentally changing some things. I'll take a closer look this weekend, already knowing that I'll come across the words deprecated a few times again and again, but we have to deal with that :) |
The incoming GPS Logger v3.0.0 will use the FileProvider by default to view tracks, also for WRPElevationChart. |
Hi @GrazianoCapelli,
Nice to hear and thanks for the feedback and 'cooperation' :). I'm waiting for version 3.0.0 (my mother, who still do a lot of hiking, too) :)
Just mentioned as a side note, Android programming runs on the side for me, so I'm certainly not that skilled in terms of system-specific things, but file handling is getting worse and worse under Android. I implemented a small browser functionality that must scan GPS specific files in the download folder for example in order to be able to browse through them. Under Android >= 11, access to the download folder seems to be severely limited for Apps targeted to Android >= 11. Time for Google to offer its own MediaStore-like access for ALL GPS-based data types, otherwise it will get very complicated at some point: for developers but for user too. |
Great GPS logger app that I'm often using when I don't have a GPS device with me.
A suggestion for improvement: if possible, the method getExternalStorageDirectory (e.g. GPSApplication.java) should be replaced in the future, as it was declared as deprecated by Google and first problems appear under current Android versions >= 10 (https://developer.android.com/reference/android/os/Environment#getExternalStorageDirectory()).
I have programmed a small free GPS Viewer app and I must embedd application android: requestLegacyExternalStorage = "true" in the manifest, otherwise my app cannot be used as an optional viewer in GPS Logger under Android 10 (no access to the file intent when calling the external viewer app). It is difficult to debug, the problem does not appear in Android Studio Emulator (emulating an Android 10 device), but on various Xiaomi phones that run on Android 10.
If I assign the requestLegacyExternalStorage option in the manifest, the viewer function also works on Xiaomi phones, but from Android 11 at the latest, this temporary option should no longer work (https://developer.android.com/training/data-storage/use-cases#opt-out-scoped-storage).
But again, nice lightweight GPS logger app that is limited to the essentials. Even my not the youngest mother is using this app sometimes when she is on a hike :).
Thanks you for sharing this app.
The text was updated successfully, but these errors were encountered: