问题描述
最近在写自定义提供其遇到了问题,第三方程序不能访问内容提供器?我猜想对外声明的语句在mainfest里面,但是比对之后发现没错,所以就不知道那里出错了?
下面是外部程序添加数据向内容提供器添加数据的代码:
Uri uri= Uri.parse('content://com.example.databasetest.provider/book');ContentValues values=new ContentValues();values.put('name','A Clash of Kings');values.put('author','George Martin');values.put('pages',1040);values.put('price',22.85);Uri newUri=getContentResolver().insert(uri,values);String newId=newUri.getPathSegments().get(1);
这是mainfest:
<provider
android:authorities='com.example.databasestest.provider' android:name='com.example.sqlite.DatabaseProvider' android:exported='true'></provider>
这是报错信息:
FATAL EXCEPTION: main Process:com.example.providertest, PID: 10088java.lang.IllegalArgumentException: Unknown URL content://com.example.databasetest.provider/book
访问的是里面一个叫book的表,如果还需要其他代码,告诉我我会提交上来!谢谢。
问题解答
回答1:在AndroidManifest文件中,<provider>必须在<application>下面,你先检查下你的<provider>是在<application>下面还是在某个<activity>下面;
试试把android:exported='true'改为android:exported='false'

