android contentprovider - Failed to find provider info for -


in encoding process encountered 1 of following exceptions:

09-12 14:12:36.327 10764-10764/cn.com.luckytry.interview e/activitythread: failed find provider info cn.com.luckytry.interview.service 09-12 14:12:36.327 10764-10764/cn.com.luckytry.interview e/contentresolver: query() unstableprovider null 

i registering , declaring permissions code in androidmanifest file androidmanifest 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 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; } 


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -