Android - 查询 SMS ContentProvider? [英] Android - Querying the SMS ContentProvider?

查看:30
本文介绍了Android - 查询 SMS ContentProvider?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前在以下 URIcontent://sms/"上注册了一个内容观察者,以侦听正在发送的传入和传出消息.

I currently register a content observer on the following URI "content://sms/" to listen out for incoming and outgoing messages being sent.

这似乎工作正常,我也尝试从 sms 数据库中删除,但我只能从以下 URI "content://sms/conversations/" 中删除整个线程

This seems to work ok and I have also tried deleting from the sms database but I can only delete an entire thread from the following URI "content://sms/conversations/"

这是我为此使用的代码

String url = "content://sms/"; 
        Uri uri = Uri.parse(url); 
        getContentResolver().registerContentObserver(uri, true, new MyContentObserver(handler));                    

}

class MyContentObserver extends ContentObserver { 

    public MyContentObserver(Handler handler) { 

        super(handler); 

    }

@Override public boolean deliverSelfNotifications() { 
    return false; 
    }

@Override public void onChange(boolean arg0) { 
    super.onChange(arg0);

     Log.v("SMS", "Notification on SMS observer"); 

    Message msg = new Message(); 
    msg.obj = "xxxxxxxxxx";

    handler.sendMessage(msg);

    Uri uriSMSURI = Uri.parse("content://sms/");
    Cursor cur = getContentResolver().query(uriSMSURI, null, null,
                 null, null);
    cur.moveToNext();
    String protocol = cur.getString(cur.getColumnIndex("protocol"));
    if(protocol == null){
           Log.d("SMS", "SMS SEND"); 
           int threadId = cur.getInt(cur.getColumnIndex("thread_id"));

           Log.d("SMS", "SMS SEND ID = " + threadId); 
           Cursor c = getContentResolver().query(Uri.parse("content://sms/outbox/" + threadId), null, null,
                   null, null);
           c.moveToNext();
           int p = cur.getInt(cur.getColumnIndex("person"));
           Log.d("SMS", "SMS SEND person= " + p); 
           //getContentResolver().delete(Uri.parse("content://sms/conversations/" + threadId), null, null);

    }
    else{
        Log.d("SMS", "SMS RECIEVE");  
         int threadIdIn = cur.getInt(cur.getColumnIndex("thread_id"));

         getContentResolver().delete(Uri.parse("content://sms/conversations/" + threadIdIn), null, null);
    }

 }


} 

但是我希望能够从 SMS Content Provider 获得收件人和消息文本,谁能告诉我如何做到这一点?

However I want to be able to get the recipricant and the message text from the SMS Content Provider, can anyone tell me how to do this?

以及如何删除一条消息而不是整个线程?

And also how to delete one message instead of an entire thread?

推荐答案

这个已经讨论过了.

要从内容提供商处读取短信,请检查:- android-1-5-reading-sms-messages

To read SMS from the Content provider check: - android-1-5-reading-sms-messages

检查此线程:

关于您的评论说您要删除整个线程而不是单个短信:您是否尝试过此代码?

About your comment saying that you are deleting a whole thread instead of a single sms: Have you tried out this code?

这篇关于Android - 查询 SMS ContentProvider?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆