• 手机版

    扫码体验手机版

  • 微信公众号

    扫码关注公众号

国内首家协议开发

软芯音视解码保护平台

在线
客服

发布
需求

在线
聊天

天盟
APP

天盟APP下载

关注
微信

微信扫一扫访问
顶部

ContentProvider访问数据出错

public class Myprovider extends ContentProvider {        //定义一个UriMatcher器private static final UriMatcher Myurimatcher=new UriMatcher(UriMatcher.NO_MATCH);private static final int QUERYSECUSS = 0;private MyopenHelper myopenHelper;static{        //定义静态代码块用来添加匹配规则/*authority:和在清单文件中自定义的必须一致         Myurimatcher.addURI("com.lianxi.myprovider", "query", QUERYSECUSS);}        @Override        public boolean onCreate() {                myopenHelper = new MyopenHelper(getContext());                return false;        }                public Cursor query(Uri uri, String[] projection, String selection,                        String[] selectionArgs, String sortOrder) {        int code=Myurimatcher.match(uri);        if (code==QUERYSECUSS) {//判断调用者传过来的uri和自己定义是否匹配                //若匹配成功把query方法实现                SQLiteDatabase sDatabase=myopenHelper.getReadableDatabase();                    Cursor cursor=sDatabase.query("info", projection, selection, selectionArgs, null, null, sortOrder);    return cursor;        }else{                throw new IllegalArgumentException("路径不匹配,请检查路径是否正确");        }                        }这是自己定义的内容提供者!

Mainactivity代码如下:
public class MainActivity extends Activity {    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);               Uri uri=Uri.parse("content://com.lianxi.myprovider/query");      Cursor cursor =getContentResolver().query(uri, null,  null,  null,  null);      if (cursor!=null && cursor.getCount()>0) {                while (cursor.moveToNext()) {                        String name=cursor.getString(1);                        String moneny=cursor.getString(2);                        System.out.println("内容解析者查询结果:name"+name+"--------moneny"+moneny);                }        }运行工程报出如下日志:

08-05 20:39:50.901: E/AndroidRuntime(828): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.lianxi.contenreciver/com.lianxi.contenreciver.MainActivity}: java.lang.SecurityException: Permission Denial: opening provider com.lianxi.createdatebase.Myprovider from ProcessRecord{41985148 828:com.lianxi.contenreciver/u0a10047} (pid=828, uid=10047) that is not exported from uid 10046求大神指教这是怎么回事。。!

免责声明:本内容仅代表回答会员见解不代表天盟观点,请谨慎对待。

版权声明:作者保留权利,不代表天盟立场。

使用道具 举报

发新帖

发布任务需求已有1031166位用户正在使用天盟网服务

发布分类: *
任务预算: *
需求内容: *
手机号码: *
任务商家报价为
  • 预算价 :
  • 成交价 :
  • 完工期 :
  • 质保期 :

* 最终任务项目以服务商报价、双方协商为准!