" date)";
ICLogger.d(createWarningMsg);
db.execSQL(createWarningMsg);
+ //创建通知表
+ String createNotification = "create table " +
+ tb_notification +
+ " (" +
+ notification_id +
+ " integer primary key autoincrement, " +
+ notification_title +
+ " text, " +
+ notification_type +
+ " integer, " +
+ notification_order +
+ " integer, " +
+ notification_date +
+ " date, " +
+ notification_create_time +
+ " date)";
+ ICLogger.d(createNotification);
+ db.execSQL(createNotification);
}
//闹钟数据库
public static final String alarm_name = "name";
public static final String alarm_later = "alarm_later";
-
//云短信数据库
public static final String tb_web_sms = "web_sms";
public static final String web_sms_id = "_id";
public static final String warning_msg_create_time = "create_time";
+ //通知数据库
+ public static final String tb_notification = "notification";
+ public static final String notification_id = "_id";
+ public static final String notification_title = "title";
+ public static final String notification_date = "date";
+ public static final String notification_type = "type";
+ public static final String notification_order = "`order`";
+ public static final String notification_create_time = "create_time";
+
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
//升级数据库
+
}
}
--- /dev/null
+package com.enqualcomm.support.provider;
+
+import android.content.ContentProvider;
+import android.content.ContentValues;
+import android.content.UriMatcher;
+import android.database.Cursor;
+import android.database.sqlite.SQLiteDatabase;
+import android.net.Uri;
+import android.support.annotation.NonNull;
+import android.support.annotation.Nullable;
+
+public class ICNotificationProvider extends ContentProvider {
+
+ public static final String PATH = "notification";
+ public static final String AUTHORITY = "com.ic.notification";
+ public static final String MEMBERS = "content://" + AUTHORITY + "/" + PATH;
+
+ private static final int MATH_CODE_TABLE = 1;
+ private static final UriMatcher sUriMatcher;
+
+ static {
+ sUriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
+ sUriMatcher.addURI(AUTHORITY, PATH, MATH_CODE_TABLE);
+ }
+
+ private ICDatabaseHelper mDatabase;
+
+ @Override
+ public boolean onCreate() {
+ mDatabase = new ICDatabaseHelper(getContext());
+ return false;
+ }
+
+ @Nullable
+ @Override
+ public Cursor query(@NonNull Uri uri, @Nullable String[] projection,
+ @Nullable String selection, @Nullable String[] selectionArgs,
+ @Nullable String sortOrder) {
+ //匹配规则
+ int match = sUriMatcher.match(uri);
+ SQLiteDatabase readableDatabase = mDatabase.getReadableDatabase();
+ if (match == MATH_CODE_TABLE) {
+ return readableDatabase.query(ICDatabaseHelper.tb_notification,
+ projection,
+ selection,
+ selectionArgs,
+ null, null, sortOrder);
+ }
+ return null;
+ }
+
+ @Nullable
+ @Override
+ public String getType(@NonNull Uri uri) {
+ return null;
+ }
+
+ @Nullable
+ @Override
+ public Uri insert(@NonNull Uri uri, @Nullable ContentValues values) {
+ int match = sUriMatcher.match(uri);
+ if (match == MATH_CODE_TABLE) {
+ SQLiteDatabase writableDatabase = mDatabase.getWritableDatabase();
+ //判断是否有存在吧,确保唯一,删除再添加吧,否则也是添加不进去的
+ writableDatabase.delete(ICDatabaseHelper.tb_notification,
+ ICDatabaseHelper.notification_id + "=?", new String[]{
+ values.getAsString(ICDatabaseHelper.notification_id)
+ });
+ long insert = writableDatabase.insert(ICDatabaseHelper.tb_notification,
+ null, values);
+ getContext().getContentResolver().notifyChange(uri, null);
+ return Uri.parse(AUTHORITY + "/" + PATH + "/" + insert);
+ }
+ return null;
+ }
+
+ @Override
+ public int delete(@NonNull Uri uri, @Nullable String selection,
+ @Nullable String[] selectionArgs) {
+ int match = sUriMatcher.match(uri);
+ if (match == MATH_CODE_TABLE) {
+ SQLiteDatabase writableDatabase = mDatabase.getWritableDatabase();
+ int delete = writableDatabase.delete(ICDatabaseHelper.tb_notification,
+ selection, selectionArgs);
+ if (delete > 0 && getContext() != null) {
+ getContext().getContentResolver().notifyChange(uri, null);
+ }
+ return delete;
+ }
+ return 0;
+ }
+
+ @Override
+ public int update(@NonNull Uri uri, @Nullable ContentValues values,
+ @Nullable String selection, @Nullable String[] selectionArgs) {
+ int match = sUriMatcher.match(uri);
+ if (match == MATH_CODE_TABLE) {
+ SQLiteDatabase writableDatabase = mDatabase.getWritableDatabase();
+ int update = writableDatabase.update(ICDatabaseHelper.tb_notification,
+ values, selection, selectionArgs);
+ if (update > 0 && getContext() != null) {
+ getContext().getContentResolver().notifyChange(uri, null);
+ }
+ return update;
+ }
+ return 0;
+ }
+
+}