0

I want to ask about how to read a DB from another app. We already have an app running on the device, but we have another project that refers to the previous DB.

I have dbAdapter.class to read the path to the DB, but I found some errors like "unable to open the database.

private static String DB_PATH = "/data/data/com.project.factory.apps/databases/"; private static final String DB_NAME = "dbData.db"; private static String DB_PATH_SDCARD = Environment.getExternalStorageDirectory() + "/data/com.project.factory.apps/databases/"; private Context myContext; public dbAdapter(Context context) { super(context, DB_NAME, null, 1); myContext = context; } public boolean createDatabase(){ if(DatabaseIsExist()) { return false; } else{ return false; } } private boolean DatabaseIsExist(){ checkDb = null; try{ String myPath = DB_PATH + DB_NAME; File directory = new File(DB_PATH_SDCARD); if(!directory.exists()) directory.mkdirs(); checkDb = SQLiteDatabase.openDatabase("/data/data/com.project.factory.apps/databases/dbData.db", null, SQLiteDatabase.NO_LOCALIZED_COLLATORS); } catch(SQLiteException e){ Log.e("File not found in data",e.toString()); return false; } return true; } public List<t_listInfo> getList() { try { dataAdapter = DaoManager.createDao(this.getConnectionSource(), t_listInfo.class); return dataAdapter.queryForAll(); } catch (Exception e) { e.printStackTrace(); return null; } } 

on MyActivity.Class

db.createDatabase(); db.getReadableDatabase(); data = db.getList(); 

I got an error in call the getList() function and need a suggestion or correction if the code was wrong.

5
  • i dont think it is possible Commented Dec 20, 2013 at 2:45
  • If there any way besides using ContentProviders? as I know the contectproviders need to change the script from the prev apps right ? because the previous apps develop by another division, we just have access only DB. Can we access by rooting the phone ?? or have another way ? Commented Dec 20, 2013 at 3:43
  • even if rooting deveice if u get access how u will root ur users device Commented Dec 20, 2013 at 3:45
  • just see on this web rratmansky.wordpress.com/?p=259&preview=true. Can we use that link ? Commented Dec 20, 2013 at 3:54
  • 1
    This is designed in this manner for this exact reason. Why should you get data to an app that is not yours or the author has not exposed. If this app is 'truly' yours then you will need to update the application to expose the data, or store the data centrally on a server and access the data from both applications. As @Shakeeb has said, yes with a rooted device you could gain access, will all of the devices you will be running on be rooted? Commented Dec 20, 2013 at 4:17

1 Answer 1

2

This is not possible. You should look into ContentProviders, this will allow you to access the data from other applications, using a syntax that allows you to query and specify the data you want.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.