-
Query the current default SMS app's package name and save it.
String defaultSmsApp = Telephony.Sms.getDefaultSmsPackage(context);
-
Request the user change the default SMS app to your app in order to
restore SMS messages (you must be the default SMS app in order to write
to the SMS Provider).
Intent intent = new Intent(context, Sms.Intents.ACTION_CHANGE_DEFAULT); intent.putExtra(Sms.Intents.EXTRA_PACKAGE_NAME, context.getPackageName()); startActivity(intent);
-
When you finish restoring all SMS messages, request the user to change
the default SMS app back to the previously selected app (saved during
step 1).
Intent intent = new Intent(context, Sms.Intents.ACTION_CHANGE_DEFAULT); intent.putExtra(Sms.Intents.EXTRA_PACKAGE_NAME, defaultSmsApp); startActivity(intent);
Advice for SMS backup & restore Android apps
Because the ability to write to the SMS Provider is restricted to the
app the user selects as the default SMS app, any existing app designed
purely to backup and restore SMS messages will currently be unable to
restore SMS messages on Android 4.4. An app that backs up and restores
SMS messages must also be set as the default SMS app so that it can
write messages in the SMS Provider. However, if the app does not also
send and receive SMS messages, then it should not remain set as the
default SMS app. So, you can provide a functional user experience with
the following design when the user opens your app to initiate a one-time
restore operation:
Labels:
Android
Post a Comment