First you must specify the path to the SD card. You can do this by creating a line like this:
public static final String DATABASE_FILE_PATH = "/sdcard";
But you have to call
Environment.getExternalStorageDirectory()
to get the root path to the SD card and use it to create the database. After that, you create the database as you wish. Here is an example
public class DatabaseHelper { private static final String TAG = "DatabaseHelper"; public static final String DATABASE_FILE_PATH = Environment.getExternalStorageDirectory(); public static final String DATABASE_NAME = "mydb"; public static final String TRACKS_TABLE = "tracks"; public static final String TRACK_INFO_TABLE = "track_info"; private static final String TRACKS_TABLE_CREATE = "create table " + TRACKS_TABLE + " (_id integer primary key autoincrement, title text not null, description text null, created_at date not null);"; private static final String TRACK_INFO_TABLE_CREATE = "create table " + TRACK_INFO_TABLE + " (_id integer primary key autoincrement, track_id integer not null, latitude real not null, longitude real not null, altitude real not null, created_at date not null);"; private SQLiteDatabase database; public DatabaseHelper() { try { database = SQLiteDatabase.openDatabase(DATABASE_FILE_PATH + File.separator + DATABASE_NAME, null,SQLiteDatabase.OPEN_READWRITE); } catch (SQLiteException ex) { Log.e(TAG, "error -- " + ex.getMessage(), ex);
And at the end, you should set the resolution in the manifest as follows: android.permission.WRITE_EXTERNAL_STORAGE
Good luck :) Arkde
source share