ContentProvider 使用sharePreference 返回数据

public class UserProvider extends ContentProvider {
    private static final int USE_INFO = 1;

    private SpCache sp;
    private UriMatcher mUriMatcher = new UriMatcher(UriMatcher.NO_MATCH);

    @Override
    public boolean onCreate() {

        sp = SpCache.createCache(getContext(), PerferenceContants.PREF_CONFIG);
        mUriMatcher.addURI("com.example.UserProvider", "use_info", USE_INFO);
        return true;
    }

    @Nullable
    @Override
    public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
        Log.d("TB", "userProvider-->" + uri);
        int code = mUriMatcher.match(uri);
        Log.d("TB", "code==>" + code);
        MatrixCursor vMatrixCursor = null;
        switch (code) {
            case UriMatcher.NO_MATCH:
                return null;
            case USE_INFO:
                String uuid = sp.getString("uuid", "");
                String sn = sp.getString("sn", "");
                String phone = sp.getString("phone", "");
                vMatrixCursor = new MatrixCursor(new String[]{"uuid", "sn", "phone"}, 1);
                vMatrixCursor.addRow(new Object[]{uuid, sn, phone});
                return vMatrixCursor;

        }
        return null;
    }

    @Nullable
    @Override
    public String getType(Uri uri) {
        return null;
    }

    @Nullable
    @Override
    public Uri insert(Uri uri, ContentValues values) {
        return null;
    }

    @Override
    public int delete(Uri uri, String selection, String[] selectionArgs) {
        return 0;
    }

    @Override
    public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
        return 0;
    }
}


你可能感兴趣的:(ContentProvider 使用sharePreference 返回数据)