Courtesy: GitHub

Room with Content Providers Sample

This sample demonstrates how to expose data stored in the Room persistence library with Android's Content Provider framework.

License

Copyright 2017 The Android Open Source Project, Inc.

Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

compileSdkVersion build_versions.target_sdk

applicationId "com.example.android.contentprovidersample"

minSdkVersion build_versions.min_sdk

targetSdkVersion build_versions.target_sdk

versionCode 1

versionName "1.0"

package com.example.android.contentprovidersample

permission

  • com.example.android.contentprovidersample.provider.READ_WRITE

MainActivity

Not very relevant to Room. This just shows data from {@link SampleContentProvider}. *

Since the data is exposed through the ContentProvider, other apps can read and write the content in a similar manner to this.

SampleContentProvider

A {@link ContentProvider} based on a Room database. *

Note that you don't need to implement a ContentProvider unless you want to expose the data outside your process or your application already uses a ContentProvider.

The authority of this content provider.

The URI for the Cheese table.

The match code for some items in the Cheese table.

The match code for an item in the Cheese table.

The URI matcher.