How can I read SMS messages from the device programmatically in Android?

后端 未结 11 2563
情深已故
情深已故 2020-11-22 02:48

I want to retrieve the SMS messages from the device and display them?

11条回答
  •  半阙折子戏
    2020-11-22 03:04

    This post is a little bit old, but here is another easy solution for getting data related to SMS content provider in Android:

    Use this lib: https://github.com/EverythingMe/easy-content-providers

    • Get all SMS:

      TelephonyProvider telephonyProvider = new TelephonyProvider(context);
      List smses = telephonyProvider.getSms(Filter.ALL).getList();
      

      Each Sms has all fields, so you can get any info you need:
      address, body, receivedDate, type(INBOX, SENT, DRAFT, ..), threadId, ...

    • Gel all MMS:

      List mmses = telephonyProvider.getMms(Filter.ALL).getList();
      
    • Gel all Thread:

      List threads = telephonyProvider.getThreads().getList();
      
    • Gel all Conversation:

      List conversations = telephonyProvider.getConversations().getList();
      

    It works with List or Cursor and there is a sample app to see how it looks and works.

    In fact, there is a support for all Android content providers like: Contacts, Call logs, Calendar, ... Full doc with all options: https://github.com/EverythingMe/easy-content-providers/wiki/Android-providers

    Hope it also helped :)

提交回复
热议问题