반응형
https://stackoverflow.com/questions/4422410/how-to-implement-a-contentobserver-for-call-logs
Here is the answer. Dont forget to register the content observer with this method:
registerContentObserver (Uri uri, boolean notifyForDescendents, ContentObserver observer)
And then you can create it like this.
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.getApplicationContext()
.getContentResolver()
.registerContentObserver(
android.provider.CallLog.Calls.CONTENT_URI, true,
new MyContentObserver(handler));
}
class MyContentObserver extends ContentObserver {
public MyContentObserver(Handler h) {
super(h);
}
@Override
public boolean deliverSelfNotifications() {
return true;
}
@Override
public void onChange(boolean selfChange) {
Log.d(LOG_TAG, "MyContentObserver.onChange("+selfChange+")");
super.onChange(selfChange);
// here you call the method to fill the list
}
}
- 5don't forget to unregister the provider in the onDestroy() method. – moonlightcheese Mar 11 '11 at 15:35
- 2in the line new RatedCallsContentObserver(handler)); where does the handler come from / why do I need this? thanks! – stefan.at.wpf May 31 '11 at 17:14
- 3just passing in new Handler() instead of handler works. I am just not sure if it's the best way, have to read on it. – stefan.at.wpf May 31 '11 at 17:20
- 1this handler parameter is to run onChange(boolean) on. onChange() will happen on the provider Handler. See the docs developer.android.com/reference/android/database/… – Roger Câmara Jun 2 '11 at 13:48
- 2@BenH If you don't unregister a previously registered observer, it will stay in memory. You will get a memory leak because the object that you registered to keeps a reference to your activity. – Maarten Oct 22 '13 at 17:34
반응형
'개발 > APP' 카테고리의 다른 글
안드로이드 AlertDialog 로 alert, confirm 구현 (0) | 2018.11.22 |
---|---|
안드로이드 MIUI 보안의 자동시작 (1) | 2018.11.22 |
안드로이드 브로드캐스트리시버 제한 업데이트(Oreo 8.0) (1) | 2018.11.22 |
안드로이드 전화 수신 발신 히스토리 (0) | 2018.11.22 |
Android 8.0 Oreo 대응 메뉴얼 (0) | 2018.11.22 |