从所有SMS区分收件箱和sentsms [英] differentiate inbox and sentsms from all sms

查看:163
本文介绍了从所有SMS区分收件箱和sentsms的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作在Android application.In我的软件,我必须列出所有的谈话,我没有,part.Each通话包含所有短信的数量。所以,我必须differtiate收件箱和sentsms所有sms.I了解以下的API可以使用它来查找收件箱和发送。

I am working on an ANdroid application.In my app I have to list all the conversations and i did that part.Each conversation is containing all sms to that number. So i have to differtiate inbox and sentsms from all sms.I know about the following api's can use to find inbox and sent.

content://sms/inbox
content://sms/sent

但我不希望使用的API来使用this.I列出的所有短信

But i don't want to use this.I listed all sms by using the api

content://sms/

我测试的参数:columnIndex的类型,地址,但它总是给了相同的结果为收件箱和outbox.And我的例子code是

I tested with the columnindex's type,address but it always gives the same result for inbox and outbox.And my sample code is

Uri SMS_INBOX = Uri.parse("content://sms");
        c = getContentResolver().query(SMS_INBOX, null, "thread_id" + " = "
                        + "3", null,
                        "date" + " ASC");
        if(c.moveToFirst()){
            count.add(c.getCount());
            for(int j=0;j<c.getCount();j++){
                System.out.println(c.getString(c.getColumnIndexOrThrow("body")).toString());
                System.out.println("new   person=="+c.getColumnIndex("person")+"type=="+c.getColumnIndexOrThrow("type"));
                c.moveToNext();
            }
        }
        c.close();

请帮我。

推荐答案

您可以使用ContentObserver这里来跟踪发送和接收消息,

You can use ContentObserver here to track sent and received message,

ContentObserver 的覆盖的onChange()方法,并得到短信类型和相应的工作。伪code可以如下图所示。

Override onChange() method of ContentObserver and get the sms type and work accordingly. Psuedo code can be as below.

Cursor cursor = mContext.getContentResolver().query(Uri
                             .parse("content://sms"), null, null, null, null);

String type = cursor.getColumnIndex("type");
if(cursor.getString(type).equalsIgnoreCase("1")){
    // sms received
 }
 else if(cursor.getString(type).equalsIgnoreCase("2")){
    //sms sent
 }

注册 ContentObserver 短信,

ContentResolver observer = this.getContentResolver();
observer.registerContentObserver(Uri.parse("content://sms"), 
                               true, new MySMSObserver(new Handler(),this));

其中, MySMSObserver 将是你的类扩展 ContentObserver 与构造具有参数作为处理程序和上下文,

Where MySMSObserver will be your class extending ContentObserver with Constructor having argument as Handler and Context,

public MySMSObserver(Handler handler, Context context) {
        super(handler);
        this.context = context;
}

这篇关于从所有SMS区分收件箱和sentsms的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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