Java Code Examples for android.content.ContentResolver#notifyChange()

The following examples show how to use android.content.ContentResolver#notifyChange() . 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: MediaStoreUtil.java    From Jockey with Apache License 2.0 6 votes vote down vote up
public static void appendToPlaylist(Context context, Playlist playlist, List<Song> songs) {
    Uri uri = MediaStore.Audio.Playlists.Members
            .getContentUri("external", playlist.getPlaylistId());
    ContentResolver resolver = context.getContentResolver();

    int startingCount = getPlaylistSize(context, playlist.getPlaylistId());

    ContentValues[] values = new ContentValues[songs.size()];
    for (int i = 0; i < songs.size(); i++) {
        values[i] = new ContentValues();
        values[i].put(MediaStore.Audio.Playlists.Members.PLAY_ORDER, startingCount + i);
        values[i].put(
                MediaStore.Audio.Playlists.Members.AUDIO_ID,
                songs.get(i).getSongId());
    }

    ignoreSingleContentUpdate();
    resolver.bulkInsert(uri, values);

    ignoreSingleContentUpdate();
    resolver.notifyChange(Uri.parse("content://media"), null);
}
 
Example 2
Source File: Source.java    From blade-player with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void addSongsToPlaylist(List<Song> songs, v.blade.library.Playlist list, OperationCallback callback)
{
    if(list.getSources().getSourceByPriority(0).getSource() != SOURCE_LOCAL_LIB) {callback.onFailure(); return;}

    int count = list.getContent().size();
    ContentValues[] values = new ContentValues[songs.size()];
    for (int i = 0; i < songs.size(); i++)
    {
        SongSources.SongSource local = songs.get(i).getSources().getLocal();
        if(local == null) {callback.onFailure(); return;}

        values[i] = new ContentValues();
        values[i].put(MediaStore.Audio.Playlists.Members.PLAY_ORDER, i + count + 1);
        values[i].put(MediaStore.Audio.Playlists.Members.AUDIO_ID, (long) songs.get(i).getSources().getLocal().getId());
    }
    Uri uri = MediaStore.Audio.Playlists.Members.getContentUri("external", (long) list.getSources().getLocal().getId());
    ContentResolver resolver = LibraryService.appContext.getContentResolver();
    int num = resolver.bulkInsert(uri, values);
    resolver.notifyChange(Uri.parse("content://media"), null);

    list.getContent().addAll(songs);

    callback.onSucess(null);
}
 
Example 3
Source File: MediaStoreUtil.java    From Jockey with Apache License 2.0 6 votes vote down vote up
public static void appendToPlaylist(Context context, Playlist playlist, Song song) {
    Uri uri = MediaStore.Audio.Playlists.Members
            .getContentUri("external", playlist.getPlaylistId());
    ContentResolver resolver = context.getContentResolver();

    ContentValues values = new ContentValues();
    values.put(MediaStore.Audio.Playlists.Members.PLAY_ORDER,
            getPlaylistSize(context, playlist.getPlaylistId()));
    values.put(MediaStore.Audio.Playlists.Members.AUDIO_ID, song.getSongId());

    ignoreSingleContentUpdate();
    resolver.insert(uri, values);

    ignoreSingleContentUpdate();
    resolver.notifyChange(Uri.parse("content://media"), null);
}
 
Example 4
Source File: DevicesProvider.java    From device-database with Apache License 2.0 5 votes vote down vote up
private void notifyUris(Uri affectedUri) {
    final ContentResolver contentResolver =
            getContext().getContentResolver();

    if (contentResolver != null) {
        contentResolver.notifyChange(affectedUri, null);
        contentResolver
                .notifyChange(DevicesContract
                        .DeviceManufacturer.CONTENT_URI, null);
    }
}
 
Example 5
Source File: MediaStoreUtil.java    From Jockey with Apache License 2.0 5 votes vote down vote up
public static void editPlaylist(Context context, Playlist playlist,
                                @Nullable List<Song> songs) {
    ignoreSingleContentUpdate();

    // Clear the playlist...
    Uri uri = MediaStore.Audio.Playlists.Members
            .getContentUri("external", playlist.getPlaylistId());
    ContentResolver resolver = context.getContentResolver();
    resolver.delete(uri, null, null);

    if (songs != null) {
        // ... Then add all of the songs to it
        ContentValues[] values = new ContentValues[songs.size()];
        for (int i = 0; i < songs.size(); i++) {
            values[i] = new ContentValues();
            values[i].put(MediaStore.Audio.Playlists.Members.PLAY_ORDER, i + 1);
            values[i].put(
                    MediaStore.Audio.Playlists.Members.AUDIO_ID,
                    songs.get(i).getSongId());
        }

        ignoreSingleContentUpdate();
        resolver.bulkInsert(uri, values);

        ignoreSingleContentUpdate();
        resolver.notifyChange(Uri.parse("content://media"), null);
    }
}
 
Example 6
Source File: SQLiteContentProvider.java    From opentasks-provider with Apache License 2.0 5 votes vote down vote up
protected void onEndTransaction(boolean callerIsSyncAdapter)
{
	Set<Uri> changed;
	synchronized (mChangedUris)
	{
		changed = new HashSet<Uri>(mChangedUris);
		mChangedUris.clear();
	}
	ContentResolver resolver = getContext().getContentResolver();
	for (Uri uri : changed)
	{
		boolean syncToNetwork = !callerIsSyncAdapter && syncToNetwork(uri);
		resolver.notifyChange(uri, null, syncToNetwork);
	}
}
 
Example 7
Source File: MusicUtil.java    From Phonograph with GNU General Public License v3.0 5 votes vote down vote up
public static void insertAlbumArt(@NonNull Context context, int albumId, String path) {
    ContentResolver contentResolver = context.getContentResolver();

    Uri artworkUri = Uri.parse("content://media/external/audio/albumart");
    contentResolver.delete(ContentUris.withAppendedId(artworkUri, albumId), null, null);

    ContentValues values = new ContentValues();
    values.put("album_id", albumId);
    values.put("_data", path);

    contentResolver.insert(artworkUri, values);
    contentResolver.notifyChange(artworkUri, null);
}
 
Example 8
Source File: ScreenUtil.java    From Aria with Apache License 2.0 5 votes vote down vote up
/**
 * 保存亮度设置状态
 */
public void saveBrightness(ContentResolver resolver, int brightness) {
  Uri uri = Settings.System
      .getUriFor("screen_brightness");
  Settings.System.putInt(resolver, "screen_brightness",
      brightness);
  // resolver.registerContentObserver(uri, true, myContentObserver);
  resolver.notifyChange(uri, null);
}
 
Example 9
Source File: SystemUtil.java    From KeyboardView with Apache License 2.0 5 votes vote down vote up
/**
 * 设置亮度(每30递增)
 *
 * @param activity
 */
public static void setBrightness(Activity activity) {
    ContentResolver resolver = activity.getContentResolver();
    Uri uri = Settings.System.getUriFor("screen_brightness");
    int nowScreenBri = getScreenBrightness(activity);
    nowScreenBri = nowScreenBri <= 225 ? nowScreenBri + 30 : 30;
    System.out.println("nowScreenBri==" + nowScreenBri);
    Settings.System.putInt(resolver, "screen_brightness", nowScreenBri);
    resolver.notifyChange(uri, null);
}
 
Example 10
Source File: ScreenUtil.java    From Android-Architecture with Apache License 2.0 5 votes vote down vote up
/**
 * 保存亮度设置状态
 *
 * @param resolver
 * @param brightness
 */
public static void saveBrightness(ContentResolver resolver, int brightness) {
    Uri uri = Settings.System.getUriFor("screen_brightness");
    Settings.System.putInt(resolver, "screen_brightness", brightness);
    // resolver.registerContentObserver(uri, true, myContentObserver);
    resolver.notifyChange(uri, null);
}
 
Example 11
Source File: SQLiteContentProvider.java    From opentasks with Apache License 2.0 5 votes vote down vote up
protected void onEndTransaction(boolean callerIsSyncAdapter)
{
    Set<Uri> changed;
    synchronized (mChangedUris)
    {
        changed = new HashSet<Uri>(mChangedUris);
        mChangedUris.clear();
    }
    ContentResolver resolver = getContext().getContentResolver();
    for (Uri uri : changed)
    {
        boolean syncToNetwork = !callerIsSyncAdapter && syncToNetwork(uri);
        resolver.notifyChange(uri, null, syncToNetwork);
    }
}
 
Example 12
Source File: MusicUtil.java    From Music-Player with GNU General Public License v3.0 5 votes vote down vote up
public static void insertAlbumArt(@NonNull Context context, int albumId, String path) {
    ContentResolver contentResolver = context.getContentResolver();

    Uri artworkUri = Uri.parse("content://media/external/audio/albumart");
    contentResolver.delete(ContentUris.withAppendedId(artworkUri, albumId), null, null);

    ContentValues values = new ContentValues();
    values.put("album_id", albumId);
    values.put("_data", path);

    contentResolver.insert(artworkUri, values);
    contentResolver.notifyChange(artworkUri, null);
}
 
Example 13
Source File: BrightnessUtils.java    From Common with Apache License 2.0 5 votes vote down vote up
/**
 * Set screen brightness
 * <p>Need to add permissions {@code <uses-permission android:name="android.permission.WRITE_SETTINGS" />}</p>
 *
 * @param brightness Brightness value
 */
public static boolean setBrightness(Context context, @IntRange(from = 0, to = 255) final int brightness) {
    ContentResolver resolver = context.getContentResolver();
    boolean b = Settings.System.putInt(resolver, Settings.System.SCREEN_BRIGHTNESS, brightness);
    resolver.notifyChange(Settings.System.getUriFor("screen_brightness"), null);
    return b;
}
 
Example 14
Source File: Utils.java    From opentasks with Apache License 2.0 4 votes vote down vote up
public static void cleanUpLists(Context context, SQLiteDatabase db, Account[] accounts, String authority)
{
    // make a list of the accounts array
    List<Account> accountList = Arrays.asList(accounts);

    db.beginTransaction();

    try
    {
        Cursor c = db.query(Tables.LISTS, new String[] { TaskListColumns._ID, TaskListSyncColumns.ACCOUNT_NAME, TaskListSyncColumns.ACCOUNT_TYPE }, null,
                null, null, null, null);

        // build a list of all task list ids that no longer have an account
        List<Long> obsoleteLists = new ArrayList<Long>();
        try
        {
            while (c.moveToNext())
            {
                String accountType = c.getString(2);
                // mark list for removal if it is non-local and the account
                // is not in accountList
                if (!TaskContract.LOCAL_ACCOUNT_TYPE.equals(accountType))
                {
                    Account account = new Account(c.getString(1), accountType);
                    if (!accountList.contains(account))
                    {
                        obsoleteLists.add(c.getLong(0));

                        // remove syncstate for this account right away
                        db.delete(Tables.SYNCSTATE, SyncState.ACCOUNT_NAME + "=? and " + SyncState.ACCOUNT_TYPE + "=?", new String[] {
                                account.name,
                                account.type });
                    }
                }
            }
        }
        finally
        {
            c.close();
        }

        if (obsoleteLists.size() == 0)
        {
            // nothing to do here
            return;
        }

        // remove all accounts in the list
        for (Long id : obsoleteLists)
        {
            if (id != null)
            {
                db.delete(Tables.LISTS, TaskListColumns._ID + "=" + id, null);
            }
        }
        db.setTransactionSuccessful();
    }
    finally
    {
        db.endTransaction();
    }
    // notify all observers

    ContentResolver cr = context.getContentResolver();
    cr.notifyChange(TaskLists.getContentUri(authority), null);
    cr.notifyChange(Tasks.getContentUri(authority), null);
    cr.notifyChange(Instances.getContentUri(authority), null);

    Utils.sendActionProviderChangedBroadCast(context, authority);
}
 
Example 15
Source File: Utils.java    From opentasks-provider with Apache License 2.0 4 votes vote down vote up
public static void cleanUpLists(Context context, SQLiteDatabase db, Account[] accounts, String authority)
{
	// make a list of the accounts array
	List<Account> accountList = Arrays.asList(accounts);

	db.beginTransaction();

	try
	{
		Cursor c = db.query(Tables.LISTS, new String[] { TaskListColumns._ID, TaskListSyncColumns.ACCOUNT_NAME, TaskListSyncColumns.ACCOUNT_TYPE }, null,
			null, null, null, null);

		// build a list of all task list ids that no longer have an account
		List<Long> obsoleteLists = new ArrayList<Long>();
		try
		{
			while (c.moveToNext())
			{
				String accountType = c.getString(2);
				// mark list for removal if it is non-local and the account
				// is not in accountList
				if (!TaskContract.LOCAL_ACCOUNT_TYPE.equals(accountType))
				{
					Account account = new Account(c.getString(1), accountType);
					if (!accountList.contains(account))
					{
						obsoleteLists.add(c.getLong(0));

						// remove syncstate for this account right away
						db.delete(Tables.SYNCSTATE, SyncState.ACCOUNT_NAME + "=? and " + SyncState.ACCOUNT_TYPE + "=?", new String[] { account.name,
							account.type });
					}
				}
			}
		}
		finally
		{
			c.close();
		}

		if (obsoleteLists.size() == 0)
		{
			// nothing to do here
			return;
		}

		// remove all accounts in the list
		for (Long id : obsoleteLists)
		{
			if (id != null)
			{
				db.delete(Tables.LISTS, TaskListColumns._ID + "=" + id, null);
			}
		}
		db.setTransactionSuccessful();
	}
	finally
	{
		db.endTransaction();
	}
	// notify all observers

	ContentResolver cr = context.getContentResolver();
	cr.notifyChange(TaskLists.getContentUri(authority), null);
	cr.notifyChange(Tasks.getContentUri(authority), null);
	cr.notifyChange(Instances.getContentUri(authority), null);

	Utils.sendActionProviderChangedBroadCast(context, authority);
}
 
Example 16
Source File: SambaDocumentsProvider.java    From samba-documents-provider with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onMountedServerChange() {
  final Uri rootsUri = DocumentsContract.buildRootsUri(AUTHORITY);
  final ContentResolver resolver = getContext().getContentResolver();
  resolver.notifyChange(rootsUri, null, false);
}
 
Example 17
Source File: BrowserProvider.java    From coursera-android with MIT License 4 votes vote down vote up
@Override
public int update(Uri url, ContentValues values, String where,
        String[] whereArgs) {
    SQLiteDatabase db = mOpenHelper.getWritableDatabase();

    int match = URI_MATCHER.match(url);
    if (match == -1 || match == URI_MATCH_SUGGEST) {
        throw new IllegalArgumentException("Unknown URL");
    }

    if (match == URI_MATCH_BOOKMARKS_ID || match == URI_MATCH_SEARCHES_ID) {
        StringBuilder sb = new StringBuilder();
        if (where != null && where.length() > 0) {
            sb.append("( ");
            sb.append(where);
            sb.append(" ) AND ");
        }
        String id = url.getPathSegments().get(1);
        sb.append("_id = ");
        sb.append(id);
        where = sb.toString();
    }

    ContentResolver cr = getContext().getContentResolver();

    // Not all bookmark-table updates should be backed up.  Look to see
    // whether we changed the title, url, or "is a bookmark" state, and
    // request a backup if so.
    if (match == URI_MATCH_BOOKMARKS_ID || match == URI_MATCH_BOOKMARKS) {
        boolean changingBookmarks = false;
        // Alterations to the bookmark field inherently change the bookmark
        // set, so we don't need to query the record; we know a priori that
        // we will need to back up this change.
        if (values.containsKey(BookmarkColumns.BOOKMARK)) {
            changingBookmarks = true;
        } else if ((values.containsKey(BookmarkColumns.TITLE)
                 || values.containsKey(BookmarkColumns.URL))
                 && values.containsKey(BookmarkColumns._ID)) {
            // If a title or URL has been changed, check to see if it is to
            // a bookmark.  The ID should have been included in the update,
            // so use it.
            Cursor cursor = cr.query(Browser.BOOKMARKS_URI,
                    new String[] { BookmarkColumns.BOOKMARK },
                    BookmarkColumns._ID + " = "
                    + values.getAsString(BookmarkColumns._ID), null, null);
            if (cursor.moveToNext()) {
                changingBookmarks = (cursor.getInt(0) != 0);
            }
            cursor.close();
        }

        // if this *is* a bookmark row we're altering, we need to back it up.
        if (changingBookmarks) {
            mBackupManager.dataChanged();
        }
    }

    int ret = db.update(TABLE_NAMES[match % 10], values, where, whereArgs);
    cr.notifyChange(url, null);
    return ret;
}
 
Example 18
Source File: MusicUtil.java    From Music-Player with GNU General Public License v3.0 4 votes vote down vote up
public static void deleteAlbumArt(@NonNull Context context, int albumId) {
    ContentResolver contentResolver = context.getContentResolver();
    Uri localUri = Uri.parse("content://media/external/audio/albumart");
    contentResolver.delete(ContentUris.withAppendedId(localUri, albumId), null, null);
    contentResolver.notifyChange(localUri, null);
}
 
Example 19
Source File: LauncherProvider.java    From TurboLauncher with Apache License 2.0 2 votes vote down vote up
/**
 * Send notification that we've deleted the {@link AppWidgetHost},
 * probably as part of the initial database creation. The receiver may
 * want to re-call {@link AppWidgetHost#startListening()} to ensure
 * callbacks are correctly set.
 */
private void sendAppWidgetResetNotify() {
    final ContentResolver resolver = mContext.getContentResolver();
    resolver.notifyChange(CONTENT_APPWIDGET_RESET_URI, null);
}
 
Example 20
Source File: LauncherProvider.java    From LB-Launcher with Apache License 2.0 2 votes vote down vote up
/**
 * Send notification that we've deleted the {@link AppWidgetHost},
 * probably as part of the initial database creation. The receiver may
 * want to re-call {@link AppWidgetHost#startListening()} to ensure
 * callbacks are correctly set.
 */
private void sendAppWidgetResetNotify() {
    final ContentResolver resolver = mContext.getContentResolver();
    resolver.notifyChange(CONTENT_APPWIDGET_RESET_URI, null);
}