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

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

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

11条回答
  •  梦谈多话
    2020-11-22 02:55

    Use Content Resolver ("content://sms/inbox") to read SMS which are in inbox.

    // public static final String INBOX = "content://sms/inbox";
    // public static final String SENT = "content://sms/sent";
    // public static final String DRAFT = "content://sms/draft";
    Cursor cursor = getContentResolver().query(Uri.parse("content://sms/inbox"), null, null, null, null);
    
    if (cursor.moveToFirst()) { // must check the result to prevent exception
        do {
           String msgData = "";
           for(int idx=0;idx

    Please add READ_SMS permission.

    I Hope it helps :)

提交回复
热议问题