tmo1 / sms-ie

SMS Import / Export is a simple Android app that imports and exports SMS and MMS messages, call logs, and contacts from and to JSON / NDJSON files.
GNU General Public License v3.0
319 stars 38 forks source link

Support for Android KitKat #126

Closed jakobcornell closed 10 months ago

jakobcornell commented 10 months ago

I'm working on upgrading from a device running Android 4.4.4 and am planning to use this app to transfer my SMS and MMS history to a new one. The app configuration has (and I think has always had) a minSdkVersion of 23 (6.0 Marshmallow), but I built the app with it set to 19, installed it on my device, and exported my SMS and MMS apparently without issue.

So it seems KitKat is supported by this app. Do you know whether that's the case? And relatedly, would there be any problem with lowering the minSdkVersion (say, to 19) to allow this app to be used on older devices? If it's useful, I could do additional testing of this app on my device.

tmo1 commented 10 months ago

The app configuration has (and I think has always had) a minSdkVersion of 23 (6.0 Marshmallow),

Correct.

Here's an excerpt of an email I wrote on Dec. 14, 2021 in response to a question about the possibility of building SMS I/E for Android 4.3:

The original requirement of API >= 23 was due to the requirement introduced there to do run-time permission requests, and the necessary code to do those checks does not run on API < 23. This should be easy to get around, by simply removing the run-time permission requests (and relying on the manifest permission declarations, as early versions of Android did):

https://developer.android.com/about/versions/marshmallow/android-6.0-changes https://devtut.github.io/android/runtime-permissions-in-api-23.html

Currently, there's also an API call to getOrCreateThreadId, introduced in API 23 as well:

https://developer.android.com/reference/android/provider/Telephony.Threads

as well as a bunch of other calls to the Telephony provider API, introduced in API 19:

https://developer.android.com/reference/android/provider/Telephony

So my guess is that getting it to work on API < 19 may require significant refactoring. Getting to 19 from 23 may be more manageable, if there's some relatively straightforward way of rewriting the call to getOrCreateThreadId and / or the code around it - see:

https://stackoverflow.com/questions/45070889/getorcreatethreadid-in-api-21

Even if there isn't, that call is only needed for importing MMS messages - exporting SMS and MMS messages, and importing SMS messages, do not require it, so if the MMS import code is simply removed, everything else should work at API 19.

Basically, the app has two function calls that require API level >= 23: requestPermissions and getOrCreateThreadId and thus will (I think) crash the app if invoked on a device with API level < 23.

When you ran the app on Android 4.4.4, I assume that you never hit the requestPermissions call, since the requirement to ask for dangerous permissions at runtime was added in Android 6.0 (API level 23), and you never hit the getOrCreateThreadId call since that's only used on import, not export.

Now that you've gotten me to consider the matter more carefully (thanks!), it seems that lowering minSdkVersion to 19 should be fairly simple - just a matter of testing for API level >= 23 before calling requestPermissions (or perhaps switching to the Activity.Compat version of requestPermissions) and disabling messages import on API level < 23. I'll try this out and update the app accordingly if it works.

jakobcornell commented 10 months ago

Awesome, thank you!

jakobcornell commented 10 months ago

It looks like the Android team has a Java backport of getOrCreateThreadId that would enable import functionality to be provided on earlier API levels. I personally have no need for import functionality on KitKat, but this might be an easy win for compatibility.

tmo1 commented 10 months ago

It looks like the Android team has a Java backport of getOrCreateThreadId that would enable import functionality to be provided on earlier API levels. I personally have no need for import functionality on KitKat, but this might be an easy win for compatibility.

Thanks! I don't think I'm going to bother with it, though, unless I can find an official documented version, especially since I doubt that there is a great need for import functionality on KitKat.