我想观看系统设置,并在其值发生变化时收到通知.Cursor类有一个setNotificationUri方法听起来不错,但它不起作用,编码也觉得很奇怪...那就是我做的:
// Create a content resolver and add a listener
ContentResolver resolver = getContentResolver();
resolver.addStatusChangeListener(ContentResolver.SYNC_OBSERVER_TYPE_SETTINGS | ContentResolver.SYNC_OBSERVER_TYPE_PENDING | ContentResolver.SYNC_OBSERVER_TYPE_ACTIVE, new MyObserver());
// I somehow need to get an instance of Cursor to use setNotificationUri in the next step...
Cursor cursor2 = resolver.query(Settings.System.CONTENT_URI, null, null, null, null);
// For testing purposes monitor all system settings
cursor2.setNotificationUri(resolver, Settings.System.CONTENT_URI);
Run Code Online (Sandbox Code Playgroud)
听众:
public class MyObserver implements SyncStatusObserver {
public void onStatusChanged(int which) {
Log.d("TEST", "status changed, which = " + which);
}
} …Run Code Online (Sandbox Code Playgroud)