Reading text from SMS, and show it as text view

╄→尐↘猪︶ㄣ 提交于 2019-12-25 08:40:25

问题


I am trying to create app, that will get the text from SMS, and use it in textview. So something like this, message is recived, i check if it is message I want, then i extract text, save it to string, and then show this string in textview. Any suggestions from where should i start, any examples plese ??


回答1:


You can start here for handling received SMS.




回答2:


First I would listen for SMS incoming, and on incoming SMS show a notification. Then if the user opens your app, update your display using this to get the data you want:

Uri allMessage = Uri.parse("content://sms/inbox");
            ContentResolver cr = getContentResolver();
            Cursor c = cr.query(allMessage, null, null, null, null);

            //shows one message
            c.moveToNext();
            //uncomment to cycle thru ALL messages... This will take AWHILE
            //while (c.moveToNext()) {
                for(int i = 0; i != c.getColumnCount(); i++){


    String columnName = c.getColumnName(i);
                String columnValue = c.getString(i);

                Log.v(TAG, "Col: " + columnName);
                Log.v(TAG, "Val: " + columnValue);
            }

        //}

Play around with it a little. It Should have all of the data you need (distinguish SMSs by timestamp)



来源:https://stackoverflow.com/questions/7372609/reading-text-from-sms-and-show-it-as-text-view

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