--- /dev/null
+package com.enqualcomm.support.provider;
+
+import android.content.Context;
+import android.database.sqlite.SQLiteDatabase;
+import android.database.sqlite.SQLiteOpenHelper;
+import android.support.annotation.Nullable;
+import android.util.Log;
+
+/**
+ * 这个helper创建的数据库是给语助用的
+ * 有Launcher的应用列表
+ * 以后可能有其他的内容
+ */
+public class AiInfoDatabaseHelper extends SQLiteOpenHelper {
+
+ public static final String name = "AiInfo";
+ public static final int version = 1;
+ private static final String TAG = "AiInfoDatabaseHelper";
+
+ public AiInfoDatabaseHelper(@Nullable Context context) {
+ super(context, name, null, version);
+ }
+
+ public static final String aTableName = "app_list";
+ public static final String aId = "_id";
+ public static final String aPackageName = "package_name";
+ public static final String aAppName = "app_name";
+ public static final String aBrandName = "brand_name";
+ public static final String aCreateTime = "create_time";
+ public static final String aUpdateTime = "update_time";
+
+ @Override
+ public void onCreate(SQLiteDatabase db) {
+ String appSql = "create table " +
+ aTableName + "(" + aId
+ + " Integer primary key autoincrement "
+ + aPackageName
+ + " text "
+ + aAppName
+ + " text "
+ + aBrandName
+ + " text "
+ + aCreateTime
+ + " date "
+ + aUpdateTime
+ + " date "
+ + ")";
+ Log.d(TAG, "sql == > " + appSql);
+ db.execSQL(appSql);
+ }
+
+ @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;
+
+/**
+ * AI智能助手的数据提供者
+ * - 目前只作了一个表,就是应用列表,用于给语音查询的应用列表
+ */
+public class AiInfoProvider extends ContentProvider {
+
+ //添加规则
+ public static final String AUTHORITY = "com.ic.ai.info";
+ public static final String PATH = "apps";
+ public static final String APPS = AUTHORITY + "/" + PATH;
+
+
+ private static UriMatcher uriMatcher;
+ public static final int MATCH_CODE = 0x1;
+
+ static {
+ uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
+ uriMatcher.addURI(AUTHORITY, PATH, MATCH_CODE);
+ }
+
+ private AiInfoDatabaseHelper aiInfoDatabaseHelper;
+
+ @Override
+ public boolean onCreate() {
+ aiInfoDatabaseHelper = new AiInfoDatabaseHelper(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 = uriMatcher.match(uri);
+ if (match == MATCH_CODE) {
+ SQLiteDatabase readableDatabase = aiInfoDatabaseHelper.getReadableDatabase();
+ return readableDatabase.query(AiInfoDatabaseHelper.aTableName,
+ 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 = uriMatcher.match(uri);
+ if (match == MATCH_CODE) {
+ SQLiteDatabase readableDatabase = aiInfoDatabaseHelper.getReadableDatabase();
+ readableDatabase.insert(AiInfoDatabaseHelper.aTableName, null, values);
+ }
+ return null;
+ }
+
+ @Override
+ public int delete(@NonNull Uri uri, @Nullable String selection,
+ @Nullable String[] selectionArgs) {
+ int match = uriMatcher.match(uri);
+ if (match == MATCH_CODE) {
+ SQLiteDatabase readableDatabase = aiInfoDatabaseHelper.getReadableDatabase();
+ return readableDatabase.delete(AiInfoDatabaseHelper.aTableName, selection, selectionArgs);
+ }
+ return 0;
+ }
+
+ @Override
+ public int update(@NonNull Uri uri, @Nullable ContentValues values,
+ @Nullable String selection, @Nullable String[] selectionArgs) {
+ int match = uriMatcher.match(uri);
+ if (match == MATCH_CODE) {
+ SQLiteDatabase readableDatabase = aiInfoDatabaseHelper.getReadableDatabase();
+ return readableDatabase.update(AiInfoDatabaseHelper.aTableName,
+ values, selection, selectionArgs);
+ }
+ return 0;
+ }
+}