如何检查收件箱中是否存在特定号码的短信 [英] how do I check if a sms for specific number is present in inbox

查看:80
本文介绍了如何检查收件箱中是否存在特定号码的短信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里的代码我能够正确读取消息,只要收件箱中存在短信xxxxxxxxxxx,但是当xxxxxxxxxx没有短信时,应用程序崩溃如何检查收件箱中是否存在xxxxxxxxxx的短信



here is the code i am able to read the message correctly whenever a sms against xxxxxxxxxxx is present in inbox but when there is no sms for xxxxxxxxxx the app crashes how do i check if sms for xxxxxxxxxx exists in inbox

StringBuilder smsBuilder = new StringBuilder();
        final String SMS_URI_INBOX = "content://sms/inbox";
        final String SMS_URI_ALL = "content://sms/";
        try {
            Uri uri = Uri.parse(SMS_URI_INBOX);
            String[] projection = new String[] { "_id", "address", "person", "body", "date", "type" };
            Cursor cur = getContentResolver().query(uri, projection, "address='xxxxxxxxxx'", null, "date desc");
            if (cur.moveToFirst()) {

                int index_Address = cur.getColumnIndex("address");
                int index_Person = cur.getColumnIndex("person");
                int index_Body = cur.getColumnIndex("body");
                int index_Date = cur.getColumnIndex("date");
                int index_Type = cur.getColumnIndex("type");
                do {
                    String strAddress = cur.getString(index_Address);
                    int intPerson = cur.getInt(index_Person);
                    String strbody = cur.getString(index_Body);
                    long longDate = cur.getLong(index_Date);
                    int int_Type = cur.getInt(index_Type);

                    strMessage=strbody;

                    smsBuilder.append("[ ");
                    smsBuilder.append(strAddress + ", ");
                    smsBuilder.append(intPerson + ", ");
                    smsBuilder.append(strbody + ", ");
                    smsBuilder.append(longDate + ", ");
                    smsBuilder.append(int_Type);
                    smsBuilder.append(" ]\n\n");
                } while (cur.moveToNext());

                if (!cur.isClosed()) {
                    cur.close();
                    cur = null;
                }
            } else {
                smsBuilder.append("no result!");
            } // end if
        }catch (SQLiteException ex) {
        //Log.d("SQLiteException",
        ex.getMessage();
    }

推荐答案

检查此解决方案。所有你需要的编辑它以检查来自该特定号码的消息是否存在。我的意思是检查光标c 是否存在。

Check this solution. All you need to edit it to check messages from that particular number exists or not. I mean check whether Cursor c exist or not.
Cursor c = cr.query(myMessage, new String[] { "_id", "address", "date",
                "body", "read" }, "address = '+9180009'", null, null);





阅读收件箱信息一个特定的数字 [ ^ ]


这篇关于如何检查收件箱中是否存在特定号码的短信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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