SMS exception caused by video group chat in android Development
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.
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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 28 29 30 31 32 33 |
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:
1 2 3 4 5 6 7 8 |
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.