android Content provider 使用时出现的错误。
错误提示信息:
java.lang.SecurityException: Permission Denial: opening provider com.example.db.PersonProvider from ProcessRecord{2c6e34f0 24384:com.dzr.other2/u0a10051} (pid=24384, uid=10051) that is not exported from uid 10050
at android.os.Parcel.readException(Parcel.java:1425)
at android.os.Parcel.readException(Parcel.java:1379)
at android.app.ActivityManagerProxy.getContentProvider(ActivityManagerNative.java:2530)
at android.app.ActivityThread.acquireProvider(ActivityThread.java:4460)
at android.app.ContextImpl$ApplicationContentResolver.acquireProvider(ContextImpl.java:1987)
at android.content.ContentResolver.acquireProvider(ContentResolver.java:1054)
at android.content.ContentResolver.insert(ContentResolver.java:860)
at com.dzr.test.AccessContentProvierTest.testInsert(AccessContentProvierTest.java:21)
at java.lang.reflect.Method.invokeNative(Native Method)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:190)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:175)
at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:555)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1661)
test代码:
源数据代码:
情况如下:
开始我已经在模拟器上启动了数据库代码。
但是过了很久后再使用测试代码,这个时候,系统提示错误参数的信息。
于是我再重新启动了下数据库的程序。
再次运行Test程序,就提示这个错误。
java.lang.SecurityException: Permission Denial: opening provider com.example.db.PersonProvider from ProcessRecord{2c6e34f0 24384:com.dzr.other2/u0a10051} (pid=24384, uid=10051) that is not exported from uid 10050
at android.os.Parcel.readException(Parcel.java:1425)
at android.os.Parcel.readException(Parcel.java:1379)
at android.app.ActivityManagerProxy.getContentProvider(ActivityManagerNative.java:2530)
at android.app.ActivityThread.acquireProvider(ActivityThread.java:4460)
at android.app.ContextImpl$ApplicationContentResolver.acquireProvider(ContextImpl.java:1987)
at android.content.ContentResolver.acquireProvider(ContentResolver.java:1054)
at android.content.ContentResolver.insert(ContentResolver.java:860)
at com.dzr.test.AccessContentProvierTest.testInsert(AccessContentProvierTest.java:21)
at java.lang.reflect.Method.invokeNative(Native Method)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:190)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:175)
at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:555)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1661)
test代码:
package com.dzr.test;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.net.Uri;
import android.test.AndroidTestCase;
public class AccessContentProvierTest extends AndroidTestCase
{
public void testInsert()throws Exception
{
Uri uri = Uri.parse("content://cn.dzr.personprovider/person");
ContentResolver resolver = this.getContext().getContentResolver();
ContentValues values = new ContentValues();
values.put("name", "laoli");
values.put("phone", "13786788939");
values.put("amount", 12212121);
resolver.insert(uri, values);
}
}源数据代码:
package com.example.db;
import com.example.service.DbOpenHelper;
import android.content.ContentProvider;
import android.content.ContentUris;
import android.content.ContentValues;
import android.content.UriMatcher;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.net.Uri;
public class PersonProvider extends ContentProvider
{
private DbOpenHelper dbOpenHelper;
private static final UriMatcher MATCHER = new UriMatcher(UriMatcher.NO_MATCH);
private static final int PERSONS = 1;
static{
MATCHER.addURI("cn.dzr.personprovider", "person", PERSONS);
}
public boolean onCreate()
{
dbOpenHelper = new DbOpenHelper(this.getContext());
return true;
}
@Override
public int delete(Uri arg0, String arg1, String[] arg2)
{
// TODO Auto-generated method stub
return 0;
}
@Override
public String getType(Uri uri)
{
// TODO Auto-generated method stub
return null;
}
@Override
public Uri insert(Uri uri, ContentValues values)
{
SQLiteDatabase db = this.dbOpenHelper.getWritableDatabase();
switch(MATCHER.match(uri))
{
case 1:
long rowid = db.insert("person", null, values);
// Uri insertUri = Uri.parse("content://cn.dzr.personprovider/person" + rowid);
Uri insertUri = ContentUris.withAppendedId(uri, rowid);
return insertUri;
default:
throw new IllegalArgumentException("this is an unknow Uri:" + uri);
}
}
@Override
public Cursor query(Uri uri, String[] projection, String selection,
String[] selectionArgs, String sortOrder)
{
// TODO Auto-generated method stub
return null;
}
@Override
public int update(Uri uri, ContentValues values, String selection,
String[] selectionArgs)
{
// TODO Auto-generated method stub
return 0;
}
}情况如下:
开始我已经在模拟器上启动了数据库代码。
但是过了很久后再使用测试代码,这个时候,系统提示错误参数的信息。
于是我再重新启动了下数据库的程序。
再次运行Test程序,就提示这个错误。
...全文
相关推荐
安卓Android源码——一个批量删除联系人的Demo.zip
安卓Android源码——一个批量删除联系人的Demo.zip
Android webview 遇到android.os.FileUriExposedException错误解决办法
主要介绍了Android webview 遇到android.os.FileUriExposedException错误解决办法的相关资料,希望通过本文能帮助到大家,让大家遇到这样的问题解决,需要的朋友可以参考下
安卓Android源码——SampleSyncAdapter.rar
安卓Android源码——SampleSyncAdapter.rar
Android代码-安卓短信助手
android-sms-assistant 安卓短信助手
安卓Android源码——导入导出txt通讯录工具.zip
安卓Android源码——导入导出txt通讯录工具.zip


