How to read inbox sms from a specific contact in android?

后端 未结 1 1586
我寻月下人不归
我寻月下人不归 2021-01-19 17:55

I am trying to read sms from content provider. I had following code

Uri uri = Uri.parse(SMS_URI_INBOX);
String whereClause = \"address=?\";
String[] wher         


        
相关标签:
1条回答
  • 2021-01-19 18:24

    Appending to @MikeM. comment, below piece of code helped me to get threadId using which I am making query in SMS Content Provider

    //Getting thread Id
    ContentResolver mContentResolver = context.getContentResolver();
    Uri uriSmsURI1 = Uri.withAppendedPath(Telephony.MmsSms.CONTENT_FILTER_BYPHONE_URI, address);
    String[] projection1 = {this.threadId};
    Cursor c1 = dbService.query(mContentResolver, uriSmsURI1, projection1, null, null, null);
    if(c1.getCount()==0) {
        log.error(methodName, "Got count: "+c1.getCount()+" While looking for ThreadID");
            return null;
    }
    String threadId = null;
    while(c1.moveToNext()){
        threadId = c1.getString(c1.getColumnIndexOrThrow(this.threadId));
    }
    c1.close();
    
    0 讨论(0)
提交回复
热议问题