I'm trying to make an app that access a SQLite table from another app with a custom content provider. I'm getting the following error:
java.lang.SecurityException: Permission Denial: reading com.example.carlos.gymlog.MiContentProvider uri content://mi.uri.porquesi/sesiones from pid=2375, uid=10064 requires android.permission.permRead, or grantUriPermission()
However, my "sender" app (the one with the database) already has the required permissions:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://ift.tt/nIICcg"
package="com.example.carlos.gymlog" >
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/MiTema" >
<activity
android:name=".Principal"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<provider android:name="MiContentProvider"
android:authorities="mi.uri.porquesi"
android:readPermission="android.permission.permRead"
android:exported="true"
android:grantUriPermissions="true"> </provider>
</application>
</manifest>
This is the code that causes the error in the "receiver" app (the one that tries to access the other):
ArrayList<Sesion> sacarDatos(Context c){
Uri cUri = Uri.parse("content://mi.uri.porquesi/sesiones");
ContentProviderClient miCP = c.getContentResolver().acquireContentProviderClient(cUri);
ArrayList<Sesion> sesiones = null;
try {
Cursor cur = miCP.query(cUri, null, null, null, null);
sesiones = new ArrayList<Sesion>();
cur.moveToFirst();
Sesion sesion = null;
do {
sesion = new Sesion(cur.getInt(0),cur.getInt(1),cur.getInt(2),cur.getInt(3));
sesiones.add(sesion);
} while (cur.moveToNext());
} catch (RemoteException e) {
e.printStackTrace();
}
return sesiones;
}
And lastly, this is my custom content provider:
public class MiContentProvider extends android.content.ContentProvider {
private static final String uri = "content://mi.uri.porquesi";
public static final Uri CONTENT_URI = Uri.parse(uri);
@Override
public boolean onCreate() {
return true;
}
@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
BaseDatosHelper miBD = new BaseDatosHelper(getContext(), "SESIONES", null, 1);
SQLiteDatabase db = miBD.getWritableDatabase();
SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
qb.setTables("SESIONES");
Cursor cur = qb.query(db,projection,selection,selectionArgs,"","",sortOrder);
cur.setNotificationUri(getContext().getContentResolver(),uri);
return cur;
}
(the rest of the methods like insert() aren't implemented, they just return null or whatever it is, I just want to select data not insert it).
Aucun commentaire:
Enregistrer un commentaire