Does SQLCipher support database access by another application (if DB is in SD-CARD)

I am trying to do one thing in SQLCiper.

This thing succeeds in SQLite Database in SD-CARD

1- created one application firstApp . with database in SD-CARD

2- a second secondApp application has been secondApp .

I am trying to read data from an SD-CARD in my second application.

Edit: - My database is in sdcard.

 public class SdcardCipherDataBase extends SQLiteOpenHelper { public static final String DATABASE_FILE_PATH = "/sdcard"; public static final String DATABASE_NAME = "sdCipherDatabase"; public final static String NAME ="name"; public final static String ADDRESS ="address"; public final static String CITY ="city"; public SdcardCipherDataBase(final Context context) { super(context,Environment.getExternalStorageDirectory()+File.separator+DATABASE_FILE_PATH + File.separator + DATABASE_NAME, null, 1); } @Override public void onCreate(SQLiteDatabase db) { try { db.execSQL( "CREATE TABLE information(_id INTEGER PRIMARY KEY AUTOINCREMENT,name TEXT, address TEXT,city TEXT);"); } catch (SQLiteException ex) { Log.e("Hello", "error -- " + ex.getMessage(), ex); } } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { // TODO Auto-generated method stub db.execSQL("DROP Table mylistdata"); onCreate(db); } } 

I use this database in the same application: -

 public void databasCollection() { SQLiteDatabase.loadLibs(this); File file = getDatabasePath("/mnt/sdcard/sdcard/sdCipherDatabase"); file.mkdir(); file.delete(); db = SQLiteDatabase.openOrCreateDatabase(file, "myapp", null); sdb = new SdcardCipherDataBase(this); sdb.getWritableDatabase("myapp"); ContentValues c = new ContentValues(); c.put(SdcardCipherDataBase.NAME,"monty"); c.put(SdcardCipherDataBase.ADDRESS,"BTM"); c.put(SdcardCipherDataBase.CITY,"Bangalore"); db.insert("information", SdcardCipherDataBase.NAME, c); db.close(); } 

but I want to use the same database in another application.

I'm trying to do something like this

 public void databaseFromOtherApp() { SQLiteDatabase.loadLibs(this); File file = getDatabasePath("/mnt/sdcard/sdcard/sdCipherDatabase"); db = SQLiteDatabase.openOrCreateDatabase(file, "myapp", null); dh = new DatabaseHelper(this); Cursor cursor = db.rawQuery("select * from information", null); cursor.moveToFirst(); String s = cursor.getString(cursor.getColumnIndex(NAME)); Toast.makeText(this,"Name is " +s, Toast.LENGTH_LONG).show(); cursor.close(); db.close(); } 

but showing an error.

  Caused by: net.sqlcipher.database.SQLiteException: no such table: information: , while compiling: select * from information 
+6
source share
1 answer

This line in your second application is incorrect:

 dh = new DatabaseHelper(this); 

You need an instance of SdcardCipherDataBase also in the second application, because this class knows about tables and table names. You are currently using a simple DatabaseHelper that does not know what to look for.

UPDATE:
Even if you could do what you need, it is not wise. As you can see, you will need to copy all your logic related to the database into any other application that uses it. What if you need a 3rd app to do the same? Copy all classes? What if you need to modify the table to add a new column? You will need to change the classes in all three applications. Typically, you want to keep the database access level in the first application and provide access to other applications through the content provider.

+2
source

All Articles