├── Readme.md
├── app
├── build.gradle
├── proguard-rules.pro
└── src
│ └── main
│ ├── java
│ └── cn
│ │ └── droidlover
│ │ └── xsharedpref
│ │ └── demo
│ │ ├── MainActivity.java
│ │ └── SecondActivity.java
│ └── res
│ ├── layout
│ ├── activity_main.xml
│ └── activity_second.xml
│ ├── mipmap-hdpi
│ └── ic_launcher.png
│ ├── mipmap-mdpi
│ └── ic_launcher.png
│ ├── mipmap-xhdpi
│ └── ic_launcher.png
│ ├── mipmap-xxhdpi
│ └── ic_launcher.png
│ ├── mipmap-xxxhdpi
│ └── ic_launcher.png
│ └── values
│ ├── colors.xml
│ ├── strings.xml
│ └── styles.xml
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ └── gradle-wrapper.properties
├── library
├── build.gradle
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── cn
│ │ └── droidlover
│ │ └── xsharedpref
│ │ ├── SharedPrefProvider.java
│ │ └── XSharedPref.java
│ └── res
│ └── values
│ └── strings.xml
└── settings.gradle
/Readme.md:
--------------------------------------------------------------------------------
1 | # XSharedPref,适用于多进程的SharedPreferences
2 |
3 | SharedPreferences底层是操作xml文件。在多进程中,每个进程都有一份SharedPreferences,因此SharedPreferences不能直接在多进程通信。为了解决此问题,将SharedPreferences的操作放在一个单独的进程中,其他进程使用ContentProvider对它进行操作,[XSharedPref](https://github.com/limedroid/XSharedPref)由此产生。
4 |
5 | ## 两个部分
6 |
7 | * SharedPrefProvider 继承了ContentProvider,实现对SharedPreferences的基本操作。
8 | * XSharedPref SharedPreferences使用工具类,其Api类似SharedPreferences。主要实现了:
9 | * getString
10 | * getInt
11 | * getLong
12 | * getFloat
13 | * getBoolean
14 | * putString
15 | * putInt
16 | * putLong
17 | * putFloat
18 | * putBoolean
19 | * remove
20 | * clear
21 | * contains
22 | 等基本操作,您可以根据自己的实际情况进行扩展。
23 |
24 | ## 使用用法
25 |
26 | 1. gradle配置
27 | compile 'cn.droidlover:xsharedpref:1.0.0'
28 |
29 | 2. AndroidManifest.xml配置ContentProvider
30 | ```xml
31 |
35 | ```
36 | process配置进程名称
37 |
38 | 3. 使用XSharedPref提供的api
39 | ```java
40 | XSharedPref.putString(this, "github_name", "https://github.com/limedroid");
41 | String gitName = XSharedPref.getString(this, "github_name", null);
42 | ```
43 | 其他的api操作也如上所述.
44 |
45 |
46 |
47 |
48 |
49 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion "23.0.2"
6 | defaultConfig {
7 | applicationId "cn.droidlover.xsharedpref.demo"
8 | minSdkVersion 15
9 | targetSdkVersion 23
10 | versionCode 1
11 | versionName "1.0"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | compile fileTree(dir: 'libs', include: ['*.jar'])
23 | compile project(':library')
24 |
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/wanglei/DevTools/Android/SDK/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/app/src/main/java/cn/droidlover/xsharedpref/demo/MainActivity.java:
--------------------------------------------------------------------------------
1 | package cn.droidlover.xsharedpref.demo;
2 |
3 | import android.app.Activity;
4 | import android.content.Intent;
5 | import android.os.Bundle;
6 | import android.view.View;
7 | import android.widget.Button;
8 |
9 | import cn.droidlover.xsharedpref.XSharedPref;
10 |
11 | public class MainActivity extends Activity {
12 |
13 | Button bt_loadUi;
14 |
15 | @Override
16 | protected void onCreate(Bundle savedInstanceState) {
17 | super.onCreate(savedInstanceState);
18 | setContentView(R.layout.activity_main);
19 |
20 | bt_loadUi = (Button) findViewById(R.id.bt_loadUi);
21 | bt_loadUi.setOnClickListener(new View.OnClickListener() {
22 | @Override
23 | public void onClick(View v) {
24 | startActivity(new Intent(MainActivity.this, SecondActivity.class));
25 | }
26 | });
27 |
28 | XSharedPref.putString(this, "user_name", "https://github.com/limedroid");
29 |
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/app/src/main/java/cn/droidlover/xsharedpref/demo/SecondActivity.java:
--------------------------------------------------------------------------------
1 | package cn.droidlover.xsharedpref.demo;
2 |
3 | import android.app.Activity;
4 | import android.os.Bundle;
5 | import android.widget.TextView;
6 |
7 | import cn.droidlover.xsharedpref.XSharedPref;
8 |
9 | public class SecondActivity extends Activity {
10 |
11 | TextView tv_val;
12 |
13 | @Override
14 | protected void onCreate(Bundle savedInstanceState) {
15 | super.onCreate(savedInstanceState);
16 | setContentView(R.layout.activity_second);
17 |
18 | tv_val = (TextView) findViewById(R.id.tv_val);
19 |
20 | String spValue = XSharedPref.getString(this, "user_name", null);
21 | tv_val.setText(spValue);
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
14 |
15 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_second.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
14 |
15 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/limedroid/XSharedPref/fd7934c452f15a1ec1c1be8bc619fa5a93a24b75/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/limedroid/XSharedPref/fd7934c452f15a1ec1c1be8bc619fa5a93a24b75/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/limedroid/XSharedPref/fd7934c452f15a1ec1c1be8bc619fa5a93a24b75/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/limedroid/XSharedPref/fd7934c452f15a1ec1c1be8bc619fa5a93a24b75/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/limedroid/XSharedPref/fd7934c452f15a1ec1c1be8bc619fa5a93a24b75/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | XSharedPref
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:2.2.1'
9 | // NOTE: Do not place your application dependencies here; they belong
10 | // in the individual module build.gradle files
11 | }
12 | }
13 |
14 | allprojects {
15 | repositories {
16 | jcenter()
17 | }
18 | }
19 |
20 | allprojects {
21 | tasks.withType(Javadoc) {
22 | options{
23 | encoding "UTF-8"
24 | charSet 'UTF-8'
25 | links "http://docs.oracle.com/javase/7/docs/api"
26 | }
27 | }
28 | }
29 |
30 | task clean(type: Delete) {
31 | delete rootProject.buildDir
32 | }
33 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 |
13 | # When configured, Gradle will run in incubating parallel mode.
14 | # This option should only be used with decoupled projects. More details, visit
15 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
16 | # org.gradle.parallel=true
17 |
18 | org.gradle.jvmargs=-Xmx1536m
19 | org.gradle.daemon=true
20 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Dec 28 10:00:20 PST 2015
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
7 |
--------------------------------------------------------------------------------
/library/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion "23.0.2"
6 |
7 | defaultConfig {
8 | minSdkVersion 15
9 | targetSdkVersion 23
10 | versionCode 1
11 | versionName "1.0"
12 |
13 |
14 | }
15 | buildTypes {
16 | release {
17 | minifyEnabled false
18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
19 | }
20 | }
21 | }
22 |
23 | dependencies {
24 | compile fileTree(dir: 'libs', include: ['*.jar'])
25 | }
26 |
27 |
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/library/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/wanglei/DevTools/Android/SDK/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/library/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/library/src/main/java/cn/droidlover/xsharedpref/SharedPrefProvider.java:
--------------------------------------------------------------------------------
1 | package cn.droidlover.xsharedpref;
2 |
3 | import android.content.ContentProvider;
4 | import android.content.ContentValues;
5 | import android.content.Context;
6 | import android.content.SharedPreferences;
7 | import android.database.Cursor;
8 | import android.net.Uri;
9 | import android.os.Bundle;
10 |
11 |
12 | public class SharedPrefProvider extends ContentProvider {
13 |
14 | private SharedPreferences preferences;
15 |
16 | public static final String SP_NAME = "xsharedPref_config";
17 |
18 | public static final String PARAM_KEY = "param_key";
19 | public static final String PARAM_VALUE = "param_value";
20 | public static final String PARAM_DEF_VALUE = "param_defValue";
21 |
22 | public static final String REPLY_VALUE = "reply_value"; //返回值
23 |
24 |
25 | @Override
26 | public boolean onCreate() {
27 | preferences = getContext().getSharedPreferences(SP_NAME, Context.MODE_PRIVATE);
28 | return false;
29 | }
30 |
31 |
32 | @Override
33 | public Bundle call(String method, String arg, Bundle extras) {
34 | Bundle replyData = null;
35 | if (extras == null) return replyData;
36 |
37 | String key = extras.getString(PARAM_KEY);
38 | replyData = new Bundle();
39 |
40 | switch (method) {
41 | case Method.GET_STRING: {
42 | String defVal = extras.getString(PARAM_DEF_VALUE);
43 | String replyVal = preferences.getString(key, defVal);
44 |
45 | replyData.putString(REPLY_VALUE, replyVal);
46 | break;
47 | }
48 |
49 | case Method.PUT_STRING: {
50 | String val = extras.getString(PARAM_VALUE);
51 | preferences.edit().putString(key, val).commit();
52 | break;
53 | }
54 |
55 | case Method.GET_INT: {
56 | int defVal = extras.getInt(PARAM_DEF_VALUE);
57 | int replyVal = preferences.getInt(key, defVal);
58 |
59 | replyData.putInt(REPLY_VALUE, replyVal);
60 | break;
61 | }
62 |
63 | case Method.PUT_INT: {
64 | int val = extras.getInt(PARAM_VALUE);
65 | preferences.edit().putInt(key, val).commit();
66 | break;
67 | }
68 |
69 | case Method.GET_FLOAT: {
70 | float defVal = extras.getFloat(PARAM_DEF_VALUE);
71 | float replyVal = preferences.getFloat(key, defVal);
72 |
73 | replyData.putFloat(REPLY_VALUE, replyVal);
74 | break;
75 | }
76 |
77 | case Method.PUT_FLOAT: {
78 | float val = extras.getFloat(PARAM_VALUE);
79 | preferences.edit().putFloat(key, val).commit();
80 | break;
81 | }
82 |
83 | case Method.GET_LONG: {
84 | long defVal = extras.getLong(PARAM_DEF_VALUE);
85 | long replyVal = preferences.getLong(key, defVal);
86 |
87 | replyData.putLong(REPLY_VALUE, replyVal);
88 | break;
89 | }
90 |
91 | case Method.PUT_LONG: {
92 | long val = extras.getLong(PARAM_VALUE);
93 | preferences.edit().putLong(key, val).commit();
94 | break;
95 | }
96 |
97 | case Method.GET_BOOLEAN: {
98 | boolean defVal = extras.getBoolean(PARAM_DEF_VALUE);
99 | boolean replyVal = preferences.getBoolean(key, defVal);
100 |
101 | replyData.putBoolean(REPLY_VALUE, replyVal);
102 | break;
103 | }
104 |
105 | case Method.PUT_BOOLEAN: {
106 | boolean val = extras.getBoolean(PARAM_VALUE);
107 | preferences.edit().putBoolean(key, val).commit();
108 | break;
109 | }
110 |
111 | case Method.REMOVE: {
112 | preferences.edit().remove(key).commit();
113 | break;
114 | }
115 |
116 | case Method.CLEAR: {
117 | preferences.edit().clear().commit();
118 | break;
119 | }
120 |
121 | case Method.CONTAINS: {
122 | boolean replyVal = preferences.contains(key);
123 |
124 | replyData.putBoolean(REPLY_VALUE, replyVal);
125 | }
126 |
127 | }
128 |
129 | return replyData;
130 | }
131 |
132 | @Override
133 | public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
134 | return null;
135 | }
136 |
137 | @Override
138 | public String getType(Uri uri) {
139 | return null;
140 | }
141 |
142 | @Override
143 | public Uri insert(Uri uri, ContentValues values) {
144 | return null;
145 | }
146 |
147 | @Override
148 | public int delete(Uri uri, String selection, String[] selectionArgs) {
149 | return 0;
150 | }
151 |
152 | @Override
153 | public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
154 | return 0;
155 | }
156 |
157 | public static class Method {
158 | public static final String PUT_STRING = "putString";
159 | public static final String GET_STRING = "getString";
160 | public static final String PUT_BOOLEAN = "putBoolean";
161 | public static final String GET_BOOLEAN = "getBoolean";
162 | public static final String PUT_FLOAT = "putFloat";
163 | public static final String GET_FLOAT = "getFloat";
164 | public static final String PUT_INT = "putInt";
165 | public static final String GET_INT = "getInt";
166 | public static final String PUT_LONG = "putLong";
167 | public static final String GET_LONG = "getLong";
168 | public static final String REMOVE = "remove";
169 | public static final String CLEAR = "clear";
170 | public static final String CONTAINS = "contains";
171 |
172 | }
173 | }
174 |
--------------------------------------------------------------------------------
/library/src/main/java/cn/droidlover/xsharedpref/XSharedPref.java:
--------------------------------------------------------------------------------
1 | package cn.droidlover.xsharedpref;
2 |
3 | import android.content.Context;
4 | import android.net.Uri;
5 | import android.os.Bundle;
6 |
7 |
8 | public class XSharedPref {
9 |
10 | private static final Uri spUri = Uri.parse("content://cn.droidlover.xsharedpref.sp");
11 |
12 | public static String getString(Context context, String key, String defValue) {
13 | Bundle reqData = new Bundle();
14 | reqData.putString(SharedPrefProvider.PARAM_KEY, key);
15 | reqData.putString(SharedPrefProvider.PARAM_DEF_VALUE, defValue);
16 |
17 | Bundle replyData = context.getContentResolver().call(spUri, SharedPrefProvider.Method.GET_STRING, null, reqData);
18 | return replyData.getString(SharedPrefProvider.REPLY_VALUE);
19 | }
20 |
21 |
22 | public static int getInt(Context context, String key, int defValue) {
23 | Bundle reqData = new Bundle();
24 | reqData.putString(SharedPrefProvider.PARAM_KEY, key);
25 | reqData.putInt(SharedPrefProvider.PARAM_DEF_VALUE, defValue);
26 |
27 | Bundle replyData = context.getContentResolver().call(spUri, SharedPrefProvider.Method.GET_INT, null, reqData);
28 | return replyData.getInt(SharedPrefProvider.REPLY_VALUE);
29 | }
30 |
31 | public static long getLong(Context context, String key, long defValue) {
32 | Bundle reqData = new Bundle();
33 | reqData.putString(SharedPrefProvider.PARAM_KEY, key);
34 | reqData.putLong(SharedPrefProvider.PARAM_DEF_VALUE, defValue);
35 |
36 | Bundle replyData = context.getContentResolver().call(spUri, SharedPrefProvider.Method.GET_LONG, null, reqData);
37 | return replyData.getLong(SharedPrefProvider.REPLY_VALUE);
38 | }
39 |
40 | public static float getFloat(Context context, String key, float defValue) {
41 | Bundle reqData = new Bundle();
42 | reqData.putString(SharedPrefProvider.PARAM_KEY, key);
43 | reqData.putFloat(SharedPrefProvider.PARAM_DEF_VALUE, defValue);
44 |
45 | Bundle replyData = context.getContentResolver().call(spUri, SharedPrefProvider.Method.GET_FLOAT, null, reqData);
46 | return replyData.getFloat(SharedPrefProvider.REPLY_VALUE);
47 | }
48 |
49 | public static boolean getBoolean(Context context, String key, boolean defValue) {
50 | Bundle reqData = new Bundle();
51 | reqData.putString(SharedPrefProvider.PARAM_KEY, key);
52 | reqData.putBoolean(SharedPrefProvider.PARAM_DEF_VALUE, defValue);
53 |
54 | Bundle replyData = context.getContentResolver().call(spUri, SharedPrefProvider.Method.GET_BOOLEAN, null, reqData);
55 | return replyData.getBoolean(SharedPrefProvider.REPLY_VALUE);
56 | }
57 |
58 |
59 | public static void putString(Context context, String key, String value) {
60 | Bundle reqData = new Bundle();
61 | reqData.putString(SharedPrefProvider.PARAM_KEY, key);
62 | reqData.putString(SharedPrefProvider.PARAM_VALUE, value);
63 |
64 | Bundle replyData = context.getContentResolver().call(spUri, SharedPrefProvider.Method.PUT_STRING, null, reqData);
65 | }
66 |
67 |
68 | public static void putInt(Context context, String key, int value) {
69 | Bundle reqData = new Bundle();
70 | reqData.putString(SharedPrefProvider.PARAM_KEY, key);
71 | reqData.putInt(SharedPrefProvider.PARAM_VALUE, value);
72 |
73 | context.getContentResolver().call(spUri, SharedPrefProvider.Method.PUT_INT, null, reqData);
74 | }
75 |
76 | public static void putLong(Context context, String key, long value) {
77 | Bundle reqData = new Bundle();
78 | reqData.putString(SharedPrefProvider.PARAM_KEY, key);
79 | reqData.putLong(SharedPrefProvider.PARAM_VALUE, value);
80 |
81 | context.getContentResolver().call(spUri, SharedPrefProvider.Method.PUT_LONG, null, reqData);
82 | }
83 |
84 | public static void putFloat(Context context, String key, float value) {
85 | Bundle reqData = new Bundle();
86 | reqData.putString(SharedPrefProvider.PARAM_KEY, key);
87 | reqData.putFloat(SharedPrefProvider.PARAM_VALUE, value);
88 |
89 | context.getContentResolver().call(spUri, SharedPrefProvider.Method.PUT_FLOAT, null, reqData);
90 | }
91 |
92 | public static void putBoolean(Context context, String key, boolean value) {
93 | Bundle reqData = new Bundle();
94 | reqData.putString(SharedPrefProvider.PARAM_KEY, key);
95 | reqData.putBoolean(SharedPrefProvider.PARAM_VALUE, value);
96 |
97 | context.getContentResolver().call(spUri, SharedPrefProvider.Method.PUT_BOOLEAN, null, reqData);
98 | }
99 |
100 | public static void remove(Context context, String key) {
101 | Bundle reqData = new Bundle();
102 | reqData.putString(SharedPrefProvider.PARAM_KEY, key);
103 |
104 | context.getContentResolver().call(spUri, SharedPrefProvider.Method.REMOVE, null, reqData);
105 | }
106 |
107 | public static void clear(Context context) {
108 | Bundle reqData = new Bundle();
109 |
110 | context.getContentResolver().call(spUri, SharedPrefProvider.Method.PUT_STRING, null, reqData);
111 | }
112 |
113 | public static boolean contains(Context context, String key) {
114 | Bundle reqData = new Bundle();
115 | reqData.putString(SharedPrefProvider.PARAM_KEY, key);
116 |
117 | Bundle replyData = context.getContentResolver().call(spUri, SharedPrefProvider.Method.CONTAINS, null, reqData);
118 | return replyData.getBoolean(SharedPrefProvider.REPLY_VALUE);
119 | }
120 |
121 | }
122 |
--------------------------------------------------------------------------------
/library/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Library
3 |
4 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':library'
2 |
--------------------------------------------------------------------------------