Listening and reciveing specific SMS message?

孤街浪徒 提交于 2019-12-06 12:37:58

NOTE: I believe this works on all phones, but not tested.

Uri allMessage = Uri.parse("content://sms/inbox");
        ContentResolver cr = getContentResolver();
        Cursor c = cr.query(allMessage, new String[]{"body"}, null, null, null);

        while (c.moveToNext()) {

            if(c.getColumnName(0).equals("body")){
                String result = c.getString(0);

            }
        }

This gets the body from every SMS message stored on the phone. If you only want to see texts from the last hour:

String selection = "date>=" + (System.currentTimeMillis()-60*60*1000);

        Uri allMessage = Uri.parse("content://sms/inbox");
        ContentResolver cr = getContentResolver();
        Cursor c = cr.query(allMessage, new String[]{"body"}, null, null, null);

        while (c.moveToNext()) {

            if(c.getColumnName(0).equals("body")){
                String result = c.getString(0);

            }
        }

from there you should be able to search thru the bodies of the SMSs for what you need or write a query (just like the date example) to search them.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!