1

In the encoding process I encountered one of the following exceptions:

09-12 14:12:36.327 10764-10764/cn.com.luckytry.interview E/ActivityThread: Failed to find provider info for cn.com.luckytry.interview.service
09-12 14:12:36.327 10764-10764/cn.com.luckytry.interview E/ContentResolver: query() unstableProvider is null

I am registering and declaring the permissions code in the AndroidManifest file AndroidManifest as follows:

 <application
    android:name=".MyApplication"
    android:allowBackup="true"
    android:icon="@mipmap/logo"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">

    <provider
        android:name=".service.InterViewPathProvider"
        android:authorities="cn.com.luckytry.interview.service"
        android:permission="cn.com.service.InterViewPathProvider"
        android:enabled="true"
        android:exported="true"
        android:process=":Provider">

    </provider>

...

</application>

 <permission
    android:name="cn.com.service.InterViewPathProvider"
    android:protectionLevel="normal" />

Customize the ContentProvider:

    public class InterViewPathProvider extends ContentProvider {

public static final String AUTHORITY = "cn.com.luckytry.interview.service";
public static final Uri PATH_CONTENT_URI = Uri.parse("content://"
        + AUTHORITY + "/path");
public static final int PATH_URI_CODE = 0;
private static final UriMatcher sUriMatcher = new UriMatcher(
        UriMatcher.NO_MATCH);

static {
    sUriMatcher.addURI(AUTHORITY, "path", PATH_URI_CODE);
}
private Context mContext;
private SQLiteDatabase mDb;

@Override
public boolean onCreate() {
    mContext = getContext();
    mDb =new DbOpenHelper(mContext).getReadableDatabase();
    return true;
}

@Nullable
@Override
public Cursor query(@NonNull Uri uri, @Nullable String[] projection, @Nullable String selection, @Nullable String[] selectionArgs, @Nullable String sortOrder) {

    String table = getTableName(uri);
    if (table == null) {
        throw new IllegalArgumentException("Unsupported URI: " + uri);
    }
    LUtil.e("query");//日志没有输出
    return mDb.query(table, projection, selection, selectionArgs, null, null, sortOrder, null);
}

...

private String getTableName(Uri uri) {
    LUtil.e("getTableName");
    String tableName = null;
    switch (sUriMatcher.match(uri)) {
        case PATH_URI_CODE:
            tableName = "interpath.db";
            break;

        default:break;
    }

    return tableName;
}

}

Services Use:

    /**
 * 解析查询结果
 * @param id
 * @return
 */
private String getQueryResult(int id) {
    Uri userUri = InterViewPathProvider.PATH_CONTENT_URI;

// Cursor cursor = db.query("news", null, "commentcount>?", new String[]{"0"}, null, null, null); String result = null;

    Cursor pathCursor = getContentResolver().query(userUri, null, "beanId=?", new String[]{id+""}, null);
    if(pathCursor!=null){
        while (pathCursor.moveToNext()) {
            result = pathCursor.getString(1);
        }
        pathCursor.close();
    }

    return  result;
}
Vicent
  • 13
  • 2

0 Answers0