contentobserver

How do I make my Android ContentObserver for ContactsContract detect a added, updated or deleted contact?

柔情痞子 提交于 2019-12-17 15:37:39
问题 I am able to get a generic notification "that there was a change to the contacts DB", but I want to know the specific record that was inserted, updated, or deleted. Following is the code that gets registered and gets the onChange notification. Unfortunately, it is not specific which makes my processing exhaustive and inefficient. Here is the code stub: if ((mNativeContactsObserver == null) && (mHandler == null)) { mHandler = new Handler(this.getMainLooper()) { }; mNativeContactsObserver = new

ContentObserver not working in android

廉价感情. 提交于 2019-12-12 16:16:30
问题 Hi I am trying with the below code.The content resolver is not working with this.Can anyone give an idea getContentResolver().registerContentObserver(MyContentProvider.CONTENT_URI,true, new ContentObserver(new Handler()){ @Override public void onChange( boolean selfChange){ showDialog(); } @Override public void onChange(boolean selfChange, Uri uri) { // Handle change. showDialog(); } }); Thanks in advance 回答1: A ContentObserver only works with a ContentProvider that calls one of the

Listening to outgoing sms not working android

倾然丶 夕夏残阳落幕 提交于 2019-12-12 13:29:20
问题 I am trying to listen to outgoing sms messages. I was following the accepted answer here but it is not working. I'm not sure where I am going wrong. I am no familiar at all with Content Observers so forgive my ignorance. I wanted to create it in a service so it would be running all the time. here is my code in that service: import android.app.Service; import android.content.ContentResolver; import android.content.Intent; import android.database.ContentObserver; import android.database.Cursor;

Content observer is being called even if the Contacts are not changed

回眸只為那壹抹淺笑 提交于 2019-12-12 08:15:01
问题 I am facing a problem that is strange, i am using the ContentObserver to catch the changes in the contacts, but the problem is that the onchange() method is called even if i am not making any changes. Here is my code : getContentResolver().registerContentObserver(ContactsContract.Contacts.CONTENT_URI, true, new MyCOntentObserver()); public class MyCOntentObserver extends ContentObserver{ public MyCOntentObserver() { super(null); } @Override public void onChange(boolean selfChange) { super

Where to register a ContentObserver which must run indefinitely?

谁说胖子不能爱 提交于 2019-12-12 06:01:45
问题 Here is how I am registering a ContentObserver to listen to sent sms: SendSmsObserver smsObeserver = (new SendSmsObserver(new Handler(), context)); ContentResolver contentResolver = context.getContentResolver(); contentResolver.registerContentObserver(Uri.parse("content://sms"), true, smsObeserver); This is the SendSmsObserver class: class SendSmsObserver extends ContentObserver { private Context context; SendSmsObserver(Handler handler, Context context) { super(handler); this.context =

How to get notify which SMS got read from native(phone) if multiple unread SMS are present in phone(native)?

雨燕双飞 提交于 2019-12-11 02:54:56
问题 If 3 unread SMS messages are present in native(phone), and user has read one of the SMS. How to identify which SMS got read(from native) in our application. Currently I am using ContentObserver and onChange() method is called when user read SMS from native(phone). I am able to get all unread SMS messages: Cursor cursor = this.getContentResolver().query(Uri.parse("content://sms/"), null, "read = 0", null, null); How to identify which SMS got read from native(phone). Any help or guidance will

getting changed uri on ContentObserver Onchange on older versions of the API [duplicate]

旧城冷巷雨未停 提交于 2019-12-10 20:13:46
问题 This question already has answers here : Closed 6 years ago . Possible Duplicate: How to get URI of inserted row in my content observer? I am using ContentObserver to listen to changes on a content provider. However, I was wondering if there is a way to get the changed URI when the OnChange method is called (instead of doing a search query inside the callback in order to find out what has changed). It seem that this is possible with the API level 16, but I have to write an API 8 compliant

Android History Content Observer

依然范特西╮ 提交于 2019-12-09 06:53:59
问题 I implemented content observer of history but it is behaving weird.For every change in history its onChange() function runs 3-5 times. static class BrowserOberser extends ContentObserver { public BrowserOberser() { super(null); } @Override public boolean deliverSelfNotifications() { return true; } @Override public void onChange(boolean selfChange) { super.onChange(selfChange); Log.d("History", "onChange: " + selfChange); } } I also registered my observer using BrowserOberser observer = new

How to handle REST calls, data persistence, syncing and observing ContentProvider

眉间皱痕 提交于 2019-12-06 01:59:38
问题 I know that this question has been asked too many times, but I think the issues I'm trying to target are a little bit different, maybe more complicated. I am going to develop an application that uses a RESTful Web Service and needs to have the following requirements: the app should show some books, their authors and their editors in lists and in detail the app should also allow searching for a book books, authors and editors are fetched from a RESTful web service every entity has to be cached

How to observe changes in database in order to update LiveData

一世执手 提交于 2019-12-05 22:36:09
I am migrating an app from a LoaderManager with Callbacks to an implementation using ViewModel and LiveData . I would like to keep using the existing SQLiteDatabase . The main implementation works OK. The Activity instantiates the ViewModel and creates an Observer which updates the View if it observes changes in the MutableLiveData that lives in the ViewModel . The ViewModel gets it data (cursor) from the SQLiteDatabase through a query using a ContentProvider . But I have other activities that can make changes to the database, while MainActivity is stopped but not destroyed. There is also a