Example usage for android.database Cursor getNotificationUri

List of usage examples for android.database Cursor getNotificationUri

Introduction

In this page you can find the example usage for android.database Cursor getNotificationUri.

Prototype

Uri getNotificationUri();

Source Link

Document

Return the URI at which notifications of changes in this Cursor's data will be delivered, as previously set by #setNotificationUri .

Usage

From source file:com.ericsender.android_nanodegree.popmovie.com.ericsender.android_nanodegree.popmovie.data.TestProvider.java

public void testBasicFavoriteQueries() {
    //first insert movies:
    Map<Long, ContentValues> listContentValues = TestUtilities.createSortedMovieValues(getContext(), "popular");
    Map<Long, Long> locationRowIds = TestUtilities.insertMovieRow(mContext, listContentValues);

    // Insert random favorites
    SQLiteDatabase db = new MovieDbHelper(getContext()).getWritableDatabase();
    Set<Long> insertedMoviedIds = new HashSet<>();
    try {// w w w.j a v a2  s.  c  o  m
        db.beginTransaction();
        while (insertedMoviedIds.isEmpty())
            for (Map.Entry<Long, ContentValues> e : listContentValues.entrySet())
                insertedMoviedIds.add(TestUtilities.generateRandomFavoritesAndInsert(db, e.getValue()));
        insertedMoviedIds.remove(null);
        db.setTransactionSuccessful();
    } finally {
        db.endTransaction();
        db.close();
    }

    // Test the basic content provider query
    Cursor favCursor = mContext.getContentResolver().query(MovieContract.FavoriteEntry.CONTENT_URI, null, null,
            null, null);

    // Make sure we get the correct cursor out of the database
    TestUtilities.validateFavoritesCursor(favCursor, listContentValues, insertedMoviedIds);

    // Has the NotificationUri been set correctly? --- we can only test this easily against API
    // level 19 or greater because getNotificationUri was added in API level 19.
    if (Build.VERSION.SDK_INT >= 19) {
        assertEquals("Error: Favoriate Query did not properly set NotificationUri",
                favCursor.getNotificationUri(), MovieContract.FavoriteEntry.buildUri());
    }
}