Android development, text message exception caused by video group chat, android text message
I am developing a program (automatic reply) for sending a text message after receiving the message. When my mobile phone starts the group chat program, my program did not send the message successfully, so I used the following code to solve this problem.
<Intent-filter android: priority = "500">
<Action android: name = "android. provider. Telephony. SMS_RECEIVED"/>
</Intent-filter>
After the message is sent, I specifically recorded the SMS log, but now the SMS receiving priority is higher than the group chat, The sent message is written to the user's SMS record after receiving the message, the following logs should be displayed:
Response Message
Received Message-this is what triggered the response
However, the log displayed by him is incorrect, as shown below:
Received Message-triggers response
Response Message
I feel that my program has been affected by the group chat program and disrupted my program. Now I don't know how to deal with it.
The following 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); }}
Solution
Try to use ContentObserver to listen to the content when the group chat program sends text messages, or test other mobile phones to see if the same problem occurs.
The following code can be used for testing:
12345678 |
context.getContentResolver().registerContentObserver(Uri.parse( "content://sms" ), true , myContentObserver); Or cursor = context.getContentResolver().query(Uri.parse( "content://sms/inbox" ), new String[] { SMS_ID, SMS_ADDRESS, SMS_READ }, "read = 0" , null , null ); cursor.registerContentObserver(myContentObserver); |
However, I cannot use a non-cursor version for some reasons in the text message/inbox. The disadvantage of the cursor-based version is that it seems to need to be kept open, so you must make sure to close it later.
In addition, whether the version is called when the read status changes.
Address: http://www.itmmd.com/201411/141.html
This article is organized and published by Meng IT personnel. The reprinted article must indicate the source.