How to register to change the SMS database?

How can I register changes to the SMS database?

I tried:

mCursor = mActivity.getContentResolver().query(Sms.CONTENT_URI, new String[] {
           Sms.ADDRESS
   }, null, null, null);
mCursor.registerDataSetObserver(mydataSetObserver);

where mydataSetObserver is implemented as follows:

 private class MyDataSetObserver extends DataSetObserver {
       public void onChanged() {
           System.out.println ("1");
       }
       public void onInvalidated() {
            System.out.println ("2");
       }
}

But when I tried to send an SMS to the emulator, MyDataSetObserver will never be called.

Could you tell me why?

Thanks.

+3
source share
2 answers

It seems that all you are trying to do is the ability to make changes to the SMS database on the device.

, , - AndroidManifest.xml. , , READ_SMS, READ_CONTACTS, .

AndroidManifest.xml :   

, WRITE_SMS, .

: , StackOverflow , , . - Android AndroidManifest.xml , , .

+3

DataSetObserver DataSetObservable . MyDataSetObserver mCursor mCursor (, requery), , (, Messaging).

, , , , content://sms/sent, , ContentObserver.

.

+1

Source: https://habr.com/ru/post/1715295/


All Articles