I am developing a program that sends a message to reply after receiving the message (Auto-reply), when my phone launches the group chat program, my program does not send the message successfully, so I use the following code to solve the problem.
<intent-filter android:priority= ">"
<action android:name= "Android.provider.Telephony.SMS_RECEIVED"/>
</intent-filter>
After the message was sent, I specifically recorded the SMS log, but now the SMS receive priority higher than group chat, sent messages are written to the user's SMS records received messages, he should show the following log:
Response Message
Received Message-this is what triggered the response
But now he's showing the wrong log, as follows
Received message-triggers Response
Response Message
I feel my program is affected by the group chat program, disrupting my program, and now I don't know what to do with it.
Here is my code:
Context.getcontentresolver (). Registercontentobserver (Uri.parse ("Content://sms"), true, Smsobserver); And this class:private class Smsobserver extends contentobserver{public smsobserver () { super (NULL); } @Override Public boolean deliverselfnotifications () { return true; } @Override public void OnChange (Boolean selfchange) { super.onchange (selfchange); if (!selfchange) //sendresponse context.getcontentresolver (). Unregistercontentobserver (this); } @Override public void OnChange (Boolean selfchange, Uri uri) { super.onchange (Selfchange, URI); if (!selfchange) //sendresponse context.getcontentresolver (). Unregistercontentobserver (this);} }
Processing methods
Try using Contentobserver to listen to the message when the group chat program is sent, or test other phones to see if the same problem occurs
Can be tested with the following code
| 12345678 |
context.getcontentresolver (). Registercontentobserver (Uri.parse (" content://sms "), true or cursor = Context.getcontentresolver (). Query (Uri.parse (" Content://sms/inbox "), &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; new string[" {sms_id, sms_address, sms_read}, &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; " read = 0 ", &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; null , &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; null cursor.registerContentObserver(myContentObserver); |
But I can't use non-cursor version, SMS/inbox for some reason. The downside of a cursor-based version is that it seems to need to be kept open, so you have to be sure to close it later.
Also, the version is called when the read state is changed.
Original address: http://www.itmmd.com/201411/141.html
This article by Meng Meng's IT person to organize the release, reprint must indicate the source.
Android development, video group chat trigger SMS exception