In the code below, I grant access to the database in app1, using Content Provider, which makes use of SQLCipher:
App1
public class StudentsProvider extends ContentProvider {
private SQLiteDatabase db;
@Override
public boolean onCreate() {
Context context = getContext();
DatabaseHelper dbHelper = new DatabaseHelper(context);
SQLiteDatabase.loadLibs(context);
db = dbHelper.getWritableDatabase("password");
return db != null;
}
In app2, I query in the app1 database:
App2
static final String PROVIDER_NAME = "com.example.a436236692.myapplication.StudentsProvider";
static final String URL = "content://" + PROVIDER_NAME + "/students";
static final Uri CONTENT_URI = Uri.parse(URL);
private void carregaResultados() {
ContentResolver cr = getContentResolver();
Cursor c = cr.query(CONTENT_URI, null, null, null, null);
if (c.moveToFirst()){
//reading db...
}
}
But I want to pass the password through the Content Provider, from app2 to app1 and change that hardcode :
db = dbHelper.getWritableDatabase ("password");
What is the best way to do this?
Thank you!