Explicitly saving new messages to inbox

2019-01-20 14:17发布

问题:

Question regarding content://sms/inbox:

1) Is it advisable to explicitly store incoming messages to inbox?
2) What if an android device has a native messaging app and my messaging app was installed to it, and then I explicitly store incoming messages to inbox, will the messages duplicate?
3) Does android automatically store new messages to inbox regardless if there is a messaging application?

Thanks.

回答1:

Regarding SMS, details vary depending on the Android version. Prior to KitKat, the SMS API was undocumented. With KitKat, the concept of a default SMS app was introduced, and the SMS API became public.

Is it advisable to explicitly store incoming messages to inbox?

  • Pre-KitKat: Yes. If your app is the main or only SMS installed, and no other app gets the SMS_RECEIVED broadcast.

  • KitKat and on: If your app is the default SMS app, then it is responsible for writing the incoming messages to the Provider. If it isn't the default, then it's irrelevant, since your app won't have write access to the Provider.

What if an android device has a native messaging app and my messaging app was installed to it, and then I explicitly store incoming messages to inbox, will the messages duplicate?

  • Pre-KitKat: Yes. Unless your app intercepts and aborts the SMS_RECEIVED broadcast, the native app will write the messages.

  • KitKat and on: Only one app can be the default at any given time, and only it has write access to the Provider. When an app is not selected as the default, it is expected to adjust its behavior accordingly.

Does android automatically store new messages to inbox regardless if there is a messaging application?

  • Pre-KitKat: No. Native messaging apps are configured to handle the writes. The system doesn't do it automatically.

  • KitKat and on: No. As mentioned, the default app is responsible for writing incoming messages to the Provider.