6-10. Sharing Your SharedPreferences

Problem

You would like your application to provide the settings values it has stored in SharedPreferences to other applications of the system and even to allow those applications to modify those settings if they have permission to do so.

Solution

(API Level 1)

Create a ContentProvider to interface your application’s SharedPreferences to the rest of the system. The settings data will be delivered using a MatrixCursor, which is an implementation that can be used for data that does not reside in a database. The ContentProvider will be protected by separate permissions to read/write the data within so that only permitted applications will have access.

How It Works

To properly demonstrate the permissions ...

Get Android Recipes: A Problem-Solution Approach, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.