Using new Telephony content provider to read SMS

后端 未结 3 1845
死守一世寂寞
死守一世寂寞 2020-12-02 19:23

According to the 4.4 SMS APIs, the new version provides functionality to:

allow apps to read and write SMS and MMS messages on the device

3条回答
  •  醉话见心
    2020-12-02 20:03

    I found this some days ago, can't remember from what site; You can only restore messages if the user has chosen to make the app the default sms app. This may or may not answer your question fully. I haven't tried this yet

    1. Query the current default SMS app's package name and save it.

      String defaultSmsApp = Telephony.Sms.getDefaultSmsPackage(context);
      
    2. 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);
      

提交回复
热议问题