A custom context is used in a database management class, not an app's contextual object:
/** * is used to support access to the database stored on the SD card **/public class DbContext extends Contextwrapper {/** * constructor * * @param base * Context */public DbContext (Context base) {super (base);} /** * Gets the database path, if it does not exist, creates the Object object * * @param name * @param mode * @param factory */@Overridepublic File Getdatabasepath (String Name) {//To determine if there is an SD card Boolean sdexist = Android.os.Environment.MEDIA_MOUNTED.equals ( Android.os.Environment.getExternalStorageState ()); if (!sdexist) {//If not present, LOG.E ("SD card management:", "SD card does not exist, please load SD card"); return null;} else {//if present//Get SD card path string dbdir = Android.os.Environment.getExternalStorageDirectory (). GetAbsolutePath ();d Bdir + = "/database";//the directory where the database is located string dbPath = Dbdir + "/" + name;//Database path//Determine if the directory exists, does not exist then create the directory file Dirfile = new file (Dbdir); Dirfile.exists ()) dirfile.mkdirs ();//The database file is created successfully boolean isfilecreatesuccess = false;//Determines if the file exists and does not exist the file is created DBFile = new File (DbPath), if (!dbfile.exists ()) {try {isfilecreatesuccess = Dbfile.createnewfile ();//Create File} catch (IOException E ) {//TODO auto-generated CATch blocke.printstacktrace ();}} Elseisfilecreatesuccess = true;//Returns the database file object if (isfilecreatesuccess) return Dbfile;elsereturn null;}} /** * Overloads this method, which is used to open the SD card on the database, Android 2.3 and below will call this method. * * @param name * @param mode * @param factory */@Overridepublic sqlitedatabase openorcreatedatabase (String name, int mod E,sqlitedatabase.cursorfactory Factory) {sqlitedatabase result = Sqlitedatabase.openorcreatedatabase ( Getdatabasepath (name), null); return result;} /** * Android 4.0 will call this method to get the database. * * @see android.content.contextwrapper#openorcreatedatabase (java.lang.String, * int, android.database.sqlite.SQLite Database.cursorfactory, * android.database.DatabaseErrorHandler) * @param name * @param mode * @param factory * @para M ErrorHandler */@Overridepublic sqlitedatabase openorcreatedatabase (String name, int mode,cursorfactory Factory, Databaseerrorhandler ErrorHandler) {sqlitedatabase result = Sqlitedatabase.openorcreatedatabase (GetDatabasePath ( name), null); return result;}}
Android creates a database on SDcard