android.database.ContentObserver Java Examples
The following examples show how to use
android.database.ContentObserver.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DCIMObserver.java From CameraV with GNU General Public License v3.0 | 6 votes |
public DCIMObserver(Context context, String parentId, ComponentName cameraComponent) { mContext = context; this.cameraComponent = cameraComponent; h = new Handler(); observers = new Vector<ContentObserver>(); observers.add(new Observer(h, MediaStore.Images.Media.EXTERNAL_CONTENT_URI)); observers.add(new Observer(h, MediaStore.Images.Media.INTERNAL_CONTENT_URI)); observers.add(new Observer(h, MediaStore.Video.Media.EXTERNAL_CONTENT_URI)); observers.add(new Observer(h, MediaStore.Video.Media.INTERNAL_CONTENT_URI)); observers.add(new Observer(h, MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI)); observers.add(new Observer(h, MediaStore.Images.Thumbnails.INTERNAL_CONTENT_URI)); observers.add(new Observer(h, MediaStore.Video.Thumbnails.EXTERNAL_CONTENT_URI)); observers.add(new Observer(h, MediaStore.Video.Thumbnails.INTERNAL_CONTENT_URI)); for(ContentObserver o : observers) { mContext.getContentResolver().registerContentObserver(((Observer) o).authority, false, o); } dcimDescriptor = new IDCIMDescriptor(parentId, cameraComponent); dcimDescriptor.startSession(); //Log.d(LOG, "DCIM OBSERVER INITED"); }
Example #2
Source File: OverlayDisplayAdapter.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
@Override public void registerLocked() { super.registerLocked(); getHandler().post(new Runnable() { @Override public void run() { getContext().getContentResolver().registerContentObserver( Settings.Global.getUriFor(Settings.Global.OVERLAY_DISPLAY_DEVICES), true, new ContentObserver(getHandler()) { @Override public void onChange(boolean selfChange) { updateOverlayDisplayDevices(); } }); updateOverlayDisplayDevices(); } }); }
Example #3
Source File: SimpleOperationTest.java From arca-android with BSD 3-Clause "New" or "Revised" License | 6 votes |
public void testSimpleOperationNotifiesChangeOnSuccess() { final AssertionLatch latch = new AssertionLatch(1); final MockContext context = new MockContext() { @Override public ContentResolver getContentResolver() { return new MockContentResolver() { @Override public void notifyChange(final Uri u, final ContentObserver o) { latch.countDown(); } }; } }; final TestSimpleOperation operation = new TestSimpleOperation(Uri.EMPTY); operation.onSuccess(context, null); latch.assertComplete(); }
Example #4
Source File: ContactsContentObserver.java From openboard with GNU General Public License v3.0 | 6 votes |
public void registerObserver(final ContactsChangedListener listener) { if (!PermissionsUtil.checkAllPermissionsGranted( mContext, Manifest.permission.READ_CONTACTS)) { Log.i(TAG, "No permission to read contacts. Not registering the observer."); // do nothing if we do not have the permission to read contacts. return; } if (DebugFlags.DEBUG_ENABLED) { Log.d(TAG, "registerObserver()"); } mContactsChangedListener = listener; mContentObserver = new ContentObserver(null /* handler */) { @Override public void onChange(boolean self) { ExecutorUtils.getBackgroundExecutor(ExecutorUtils.KEYBOARD) .execute(ContactsContentObserver.this); } }; final ContentResolver contentResolver = mContext.getContentResolver(); contentResolver.registerContentObserver(Contacts.CONTENT_URI, true, mContentObserver); }
Example #5
Source File: RxChangesObserverTest.java From storio with Apache License 2.0 | 6 votes |
@Test public void shouldDoNothingIfUriListEmpty() { for (int sdkVersion = MIN_SDK_VERSION; sdkVersion < MAX_SDK_VERSION; sdkVersion++) { ContentResolver contentResolver = mock(ContentResolver.class); Disposable disposable = RxChangesObserver .observeChanges( contentResolver, Collections.<Uri>emptySet(), mock(Handler.class), sdkVersion, BackpressureStrategy.MISSING ) .subscribe(); disposable.dispose(); verify(contentResolver, never()).registerContentObserver(any(Uri.class), anyBoolean(), any(ContentObserver.class)); verify(contentResolver, never()).unregisterContentObserver(any(ContentObserver.class)); } }
Example #6
Source File: DefaultStorIOContentResolverTest.java From storio with Apache License 2.0 | 6 votes |
@Test public void shouldUseCustomHandlerForContentObservers() { ContentResolver contentResolver = mock(ContentResolver.class); ArgumentCaptor<ContentObserver> observerArgumentCaptor = ArgumentCaptor.forClass(ContentObserver.class); doNothing().when(contentResolver) .registerContentObserver(any(Uri.class), anyBoolean(), observerArgumentCaptor.capture()); Handler handler = mock(Handler.class); StorIOContentResolver storIOContentResolver = DefaultStorIOContentResolver.builder() .contentResolver(contentResolver) .contentObserverHandler(handler) .defaultRxScheduler(null) .build(); Disposable disposable = storIOContentResolver.observeChangesOfUri(mock(Uri.class), LATEST).subscribe(); assertThat(observerArgumentCaptor.getAllValues()).hasSize(1); ContentObserver contentObserver = observerArgumentCaptor.getValue(); Object actualHandler = ReflectionHelpers.getField(contentObserver, "mHandler"); assertThat(actualHandler).isEqualTo(handler); disposable.dispose(); }
Example #7
Source File: GeofenceManager.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
public GeofenceManager(Context context, LocationBlacklist blacklist) { mContext = context; mLocationManager = (LocationManager) mContext.getSystemService(Context.LOCATION_SERVICE); mAppOps = (AppOpsManager)mContext.getSystemService(Context.APP_OPS_SERVICE); PowerManager powerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE); mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG); mHandler = new GeofenceHandler(); mBlacklist = blacklist; mResolver = mContext.getContentResolver(); updateMinInterval(); mResolver.registerContentObserver( Settings.Global.getUriFor( Settings.Global.LOCATION_BACKGROUND_THROTTLE_PROXIMITY_ALERT_INTERVAL_MS), true, new ContentObserver(mHandler) { @Override public void onChange(boolean selfChange) { synchronized (mLock) { updateMinInterval(); } } }, UserHandle.USER_ALL); }
Example #8
Source File: GlobalSettingsToPropertiesMapper.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
void updatePropertiesFromGlobalSettings() { for (String[] entry : mGlobalSettingsMapping) { final String settingName = entry[0]; final String propName = entry[1]; Uri settingUri = Settings.Global.getUriFor(settingName); Preconditions.checkNotNull(settingUri, "Setting " + settingName + " not found"); ContentObserver co = new ContentObserver(null) { @Override public void onChange(boolean selfChange) { updatePropertyFromSetting(settingName, propName); } }; updatePropertyFromSetting(settingName, propName); mContentResolver.registerContentObserver(settingUri, false, co); } }
Example #9
Source File: UsbDeviceDetachedReceiver.java From fdroidclient with GNU General Public License v3.0 | 6 votes |
@RequiresApi(api = 19) @Override public void onReceive(Context context, Intent intent) { if (Build.VERSION.SDK_INT < 19) { return; } if (intent == null || TextUtils.isEmpty(intent.getAction()) || !UsbManager.ACTION_USB_DEVICE_DETACHED.equals(intent.getAction())) { Log.i(TAG, "ignoring irrelevant intent: " + intent); return; } Log.i(TAG, "handling intent: " + intent); final ContentResolver contentResolver = context.getContentResolver(); NearbyViewBinder.updateUsbOtg(context); for (ContentObserver contentObserver : contentObservers.values()) { contentResolver.unregisterContentObserver(contentObserver); } }
Example #10
Source File: Observers.java From SQLite with Apache License 2.0 | 6 votes |
public <T> void registerObserver(@NonNull Context context, @NonNull Table<T> table, @NonNull final BasicTableObserver observer) { ContentObserver contentObserver = new DatabaseObserver() { @Override public void onChange(boolean selfChange) { super.onChange(selfChange); MainHandler.getHandler().post(new Runnable() { @Override public void run() { observer.onTableChanged(); } }); } }; context.getContentResolver().registerContentObserver(table.getUri(), false, contentObserver); mObservers.add(new Pair<Object, ContentObserver>(observer, contentObserver)); }
Example #11
Source File: ConversationDataSource.java From mollyim-android with GNU General Public License v3.0 | 6 votes |
private ConversationDataSource(@NonNull Context context, long threadId, @NonNull Invalidator invalidator, @NonNull DataUpdatedCallback dataUpdateCallback) { this.context = context; this.threadId = threadId; this.dataUpdateCallback = dataUpdateCallback; ContentObserver contentObserver = new ContentObserver(null) { @Override public void onChange(boolean selfChange) { invalidate(); context.getContentResolver().unregisterContentObserver(this); } }; invalidator.observe(() -> { invalidate(); context.getContentResolver().unregisterContentObserver(contentObserver); }); context.getContentResolver().registerContentObserver(DatabaseContentProviders.Conversation.getUriForThread(threadId), true, contentObserver); }
Example #12
Source File: ValidateNotificationPeople.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
public void initialize(Context context, NotificationUsageStats usageStats) { if (DEBUG) Slog.d(TAG, "Initializing " + getClass().getSimpleName() + "."); mUserToContextMap = new ArrayMap<>(); mBaseContext = context; mUsageStats = usageStats; mPeopleCache = new LruCache<String, LookupResult>(PEOPLE_CACHE_SIZE); mEnabled = ENABLE_PEOPLE_VALIDATOR && 1 == Settings.Global.getInt( mBaseContext.getContentResolver(), SETTING_ENABLE_PEOPLE_VALIDATOR, 1); if (mEnabled) { mHandler = new Handler(); mObserver = new ContentObserver(mHandler) { @Override public void onChange(boolean selfChange, Uri uri, int userId) { super.onChange(selfChange, uri, userId); if (DEBUG || mEvictionCount % 100 == 0) { if (VERBOSE) Slog.i(TAG, "mEvictionCount: " + mEvictionCount); } mPeopleCache.evictAll(); mEvictionCount++; } }; mBaseContext.getContentResolver().registerContentObserver(Contacts.CONTENT_URI, true, mObserver, UserHandle.USER_ALL); } }
Example #13
Source File: ModRotationFix.java From SwipeBack with GNU General Public License v3.0 | 5 votes |
static void fixOnActivityCreate(Activity activity) { boolean isRotationLocked = System.getInt(activity.getContentResolver(), System.ACCELEROMETER_ROTATION, 0) == 0; if (!isRotationLocked) { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR); } ContentObserver observer = new RotateObserver(activity, new RotateHandler(activity)); activity.getContentResolver().registerContentObserver(System.getUriFor(System.ACCELEROMETER_ROTATION), false, observer); setAdditionalInstanceField(activity, "rotateObserver", observer); }
Example #14
Source File: ContentResolver.java From AndroidComponentPlugin with Apache License 2.0 | 5 votes |
/** @hide - designated user version */ public final void registerContentObserver(Uri uri, boolean notifyForDescendents, ContentObserver observer, @UserIdInt int userHandle) { try { getContentService().registerContentObserver(uri, notifyForDescendents, observer.getContentObserver(), userHandle, mTargetSdkVersion); } catch (RemoteException e) { } }
Example #15
Source File: ContentResolver.java From AndroidComponentPlugin with Apache License 2.0 | 5 votes |
/** * Unregisters a change observer. * * @param observer The previously registered observer that is no longer needed. * @see #registerContentObserver */ public final void unregisterContentObserver(@NonNull ContentObserver observer) { Preconditions.checkNotNull(observer, "observer"); try { IContentObserver contentObserver = observer.releaseContentObserver(); if (contentObserver != null) { getContentService().unregisterContentObserver( contentObserver); } } catch (RemoteException e) { } }
Example #16
Source File: UriNotifierTest.java From squidb with Apache License 2.0 | 5 votes |
private AtomicBoolean listenTo(Uri uri, boolean notifyForDescendants) { final AtomicBoolean gotUriNotification = new AtomicBoolean(false); ContentObserver observer = new ContentObserver(null) { @Override public void onChange(boolean selfChange) { gotUriNotification.set(true); super.onChange(selfChange); } }; observers.add(observer); ContextProvider.getContext().getContentResolver().registerContentObserver(uri, notifyForDescendants, observer); return gotUriNotification; }
Example #17
Source File: MainActivity.java From Android-Basics-Codes with Artistic License 2.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); getContentResolver().registerContentObserver(Uri.parse("content://cn.itcast.person"), true, new ContentObserver(new Handler()) { @Override public void onChange(boolean selfChange) { // TODO Auto-generated method stub super.onChange(selfChange); System.out.println("01��Ŀ���ݿ����ݸı�"); } }); }
Example #18
Source File: AndroidWordLevelSpellCheckerSession.java From openboard with GNU General Public License v3.0 | 5 votes |
AndroidWordLevelSpellCheckerSession(final AndroidSpellCheckerService service) { mService = service; final ContentResolver cres = service.getContentResolver(); mObserver = new ContentObserver(null) { @Override public void onChange(boolean self) { mSuggestionsCache.clearCache(); } }; cres.registerContentObserver(Words.CONTENT_URI, true, mObserver); }
Example #19
Source File: UriNotifierTest.java From squidb with Apache License 2.0 | 5 votes |
@Override protected void setUp() throws Exception { super.setUp(); database.unregisterAllDataChangedNotifiers(); for (ContentObserver observer : observers) { ContextProvider.getContext().getContentResolver().unregisterContentObserver(observer); } }
Example #20
Source File: HapticFeedbackController.java From PersianDateRangePicker with Apache License 2.0 | 5 votes |
public HapticFeedbackController(Context context) { mContext = context; mContentObserver = new ContentObserver(null) { @Override public void onChange(boolean selfChange) { mIsGloballyEnabled = checkGlobalSetting(mContext); } }; }
Example #21
Source File: WifiDisplayController.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
public WifiDisplayController(Context context, Handler handler, Listener listener) { mContext = context; mHandler = handler; mListener = listener; mWifiP2pManager = (WifiP2pManager)context.getSystemService(Context.WIFI_P2P_SERVICE); mWifiP2pChannel = mWifiP2pManager.initialize(context, handler.getLooper(), null); IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION); intentFilter.addAction(WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION); intentFilter.addAction(WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION); intentFilter.addAction(WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION); context.registerReceiver(mWifiP2pReceiver, intentFilter, null, mHandler); ContentObserver settingsObserver = new ContentObserver(mHandler) { @Override public void onChange(boolean selfChange, Uri uri) { updateSettings(); } }; final ContentResolver resolver = mContext.getContentResolver(); resolver.registerContentObserver(Settings.Global.getUriFor( Settings.Global.WIFI_DISPLAY_ON), false, settingsObserver); resolver.registerContentObserver(Settings.Global.getUriFor( Settings.Global.WIFI_DISPLAY_CERTIFICATION_ON), false, settingsObserver); resolver.registerContentObserver(Settings.Global.getUriFor( Settings.Global.WIFI_DISPLAY_WPS_CONFIG), false, settingsObserver); updateSettings(); }
Example #22
Source File: ContentResolver.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
/** * Notify registered observers within the designated user(s) that a row was updated. * * @hide */ public void notifyChange(@NonNull Uri uri, ContentObserver observer, boolean syncToNetwork, @UserIdInt int userHandle) { try { getContentService().notifyChange( uri, observer == null ? null : observer.getContentObserver(), observer != null && observer.deliverSelfNotifications(), syncToNetwork ? NOTIFY_SYNC_TO_NETWORK : 0, userHandle, mTargetSdkVersion); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } }
Example #23
Source File: HapticFeedbackController.java From MaterialDateRangePicker with Apache License 2.0 | 5 votes |
public HapticFeedbackController(Context context) { mContext = context; mContentObserver = new ContentObserver(null) { @Override public void onChange(boolean selfChange) { mIsGloballyEnabled = checkGlobalSetting(mContext); } }; }
Example #24
Source File: BluetoothManagerService.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
private void registerForBleScanModeChange() { ContentObserver contentObserver = new ContentObserver(null) { @Override public void onChange(boolean selfChange) { if (isBleScanAlwaysAvailable()) { // Nothing to do return; } // BLE scan is not available. disableBleScanMode(); clearBleApps(); try { mBluetoothLock.readLock().lock(); if (mBluetooth != null) { addActiveLog(BluetoothProtoEnums.ENABLE_DISABLE_REASON_APPLICATION_REQUEST, mContext.getPackageName(), false); mBluetooth.onBrEdrDown(); } } catch (RemoteException e) { Slog.e(TAG, "error when disabling bluetooth", e); } finally { mBluetoothLock.readLock().unlock(); } } }; mContentResolver.registerContentObserver( Settings.Global.getUriFor(Settings.Global.BLE_SCAN_ALWAYS_AVAILABLE), false, contentObserver); }
Example #25
Source File: TelecomLoaderService.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
private void registerDefaultAppNotifier() { final PackageManagerInternal packageManagerInternal = LocalServices.getService( PackageManagerInternal.class); // Notify the package manager on default app changes final Uri defaultSmsAppUri = Settings.Secure.getUriFor( Settings.Secure.SMS_DEFAULT_APPLICATION); final Uri defaultDialerAppUri = Settings.Secure.getUriFor( Settings.Secure.DIALER_DEFAULT_APPLICATION); ContentObserver contentObserver = new ContentObserver( new Handler(Looper.getMainLooper())) { @Override public void onChange(boolean selfChange, Uri uri, int userId) { if (defaultSmsAppUri.equals(uri)) { ComponentName smsComponent = SmsApplication.getDefaultSmsApplication( mContext, true); if (smsComponent != null) { packageManagerInternal.grantDefaultPermissionsToDefaultSmsApp( smsComponent.getPackageName(), userId); } } else if (defaultDialerAppUri.equals(uri)) { String packageName = DefaultDialerManager.getDefaultDialerApplication( mContext); if (packageName != null) { packageManagerInternal.grantDefaultPermissionsToDefaultDialerApp( packageName, userId); } updateSimCallManagerPermissions(packageManagerInternal, userId); } } }; mContext.getContentResolver().registerContentObserver(defaultSmsAppUri, false, contentObserver, UserHandle.USER_ALL); mContext.getContentResolver().registerContentObserver(defaultDialerAppUri, false, contentObserver, UserHandle.USER_ALL); }
Example #26
Source File: HapticFeedbackController.java From StyleableDateTimePicker with MIT License | 5 votes |
public HapticFeedbackController(Context context) { mContext = context; mContentObserver = new ContentObserver(null) { @Override public void onChange(boolean selfChange) { mIsGloballyEnabled = checkGlobalSetting(mContext); } }; }
Example #27
Source File: ContentResolver.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
/** * Unregisters a change observer. * * @param observer The previously registered observer that is no longer needed. * @see #registerContentObserver */ public final void unregisterContentObserver(@NonNull ContentObserver observer) { Preconditions.checkNotNull(observer, "observer"); try { IContentObserver contentObserver = observer.releaseContentObserver(); if (contentObserver != null) { getContentService().unregisterContentObserver( contentObserver); } } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } }
Example #28
Source File: MergeCursor.java From libcommon with Apache License 2.0 | 5 votes |
@Override public void unregisterContentObserver(final ContentObserver observer) { synchronized (mCursors) { for (final Cursor cursor: mCursors) { if (cursor != null) { cursor.unregisterContentObserver(observer); } } } }
Example #29
Source File: HapticFeedbackController.java From AlarmOn with Apache License 2.0 | 5 votes |
public HapticFeedbackController(Context context) { mContext = context; mContentObserver = new ContentObserver(null) { @Override public void onChange(boolean selfChange) { mIsGloballyEnabled = checkGlobalSetting(mContext); } }; }
Example #30
Source File: RxChangesObserverTest.java From storio with Apache License 2.0 | 5 votes |
@Test public void shouldUnregisterContentObserversForEachUriAfterDisposingFromFlowableOnSdkVersionLowerThan16() { for (int sdkVersion = MIN_SDK_VERSION; sdkVersion < 16; sdkVersion++) { ContentResolver contentResolver = mock(ContentResolver.class); Set<Uri> uris = new HashSet<Uri>(3); uris.add(mock(Uri.class)); uris.add(mock(Uri.class)); uris.add(mock(Uri.class)); final Map<Uri, ContentObserver> contentObservers = new HashMap<Uri, ContentObserver>(3); doAnswer(new Answer() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { contentObservers.put((Uri) invocation.getArguments()[0], (ContentObserver) invocation.getArguments()[2]); return null; } }).when(contentResolver).registerContentObserver(any(Uri.class), eq(true), any(ContentObserver.class)); Disposable disposable = RxChangesObserver .observeChanges( contentResolver, uris, mock(Handler.class), sdkVersion, BackpressureStrategy.MISSING ) .subscribe(); // Should not unregister before dispose from Disposable verify(contentResolver, never()).unregisterContentObserver(any(ContentObserver.class)); disposable.dispose(); for (Uri uri : uris) { // Assert that ContentObserver for each uri was unregistered verify(contentResolver).unregisterContentObserver(contentObservers.get(uri)); } } }