I am trying one thing in SQLCiper.
This thing is success in SQLite Database in SD-CARD
1- created one app firstApp
. with Database in SD-CARD
2- created second app secondApp
.
i am trying to read data from SD-CARD in my second App.
Edit:- My database 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 am using this Database in same app:-
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 same database in other app aslo.
i am trying to do some thing 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 error .
Caused by: net.sqlcipher.database.SQLiteException: no such table: information: , while compiling: select * from information