Aalok Sharma
Aalok Sharma

Reputation: 1025

Saving the sqlite databse in android internal memory

So I've googled around tried a few examples as well, but so far I haven't been able to find any source that can provide me any knowledge whether I can save my sqlite db in any other folder in the device's internal memory for example in the "/system" folder, I know that its possible to save it in the sd card by simply doing the following

public class DatabaseHandler extends SQLiteOpenHelper {

    // All Static variables
    // Database Version
    private static final int DATABASE_VERSION = 1;

    // Database Name
    private static final String DATABASE_NAME = "contactsManager";

    // Contacts table name
    private static final String TABLE_CONTACTS = "contacts";

    // Contacts Table Columns names
    private static final String KEY_ID = "id";
    private static final String KEY_NAME = "name";
    private static final String KEY_PH_NO = "phone_number";

    public DatabaseHandler(Context context) {
        super(context, "sd card path here "+DATABASE_NAME, null, DATABASE_VERSION);
    }

    // Creating Tables
    @Override
    public void onCreate(SQLiteDatabase db) {
        String CREATE_CONTACTS_TABLE = "CREATE TABLE " + TABLE_CONTACTS + "("
                + KEY_ID + " INTEGER PRIMARY KEY," + KEY_NAME + " TEXT,"
                + KEY_PH_NO + " TEXT" + ")";
        db.execSQL(CREATE_CONTACTS_TABLE);
    }

But is there any way that i can save the db in the internal memory like in the "/system" folder ?

Upvotes: 1

Views: 909

Answers (2)

Saqib Vohra
Saqib Vohra

Reputation: 366

If you have root permissions, you can access the folder simply like /system/app Here is a similar thread, you may find it useful. :)

how to get access of android root directory (/system/app) programatically?

P.S: Duplicating comment as i cant paste link their.

Upvotes: 0

CommonsWare
CommonsWare

Reputation: 1006614

But is there any way that i can save the db in the internal memory like in the "/system" folder ?

No, because you do not have read or write access to that directory.

Upvotes: 2

Related Questions