Home>

First add permissions to the manifest:

<uses-permission android:name="android.permission.write_external_storage" />
<Uses-permission android:name="android.permission.mount_unmount_filesystems" />

Then add the method in mainactivity:

sqlitedatabase db;
private final string database_path=android.os.environment
 .getexternalstoragedirectory (). getabsolutepath () + "/vote";
private string database_filename="db_vote.db";
//Initialize the database
private sqlitedatabase opendatabase () {
  try {
   string databasefilename=database_path + "/" + database_filename;
   file dir=new file (database_path);
   if (! dir.exists ())
    dir.mkdir ();
   if (! (new file (databasefilename)). exists ()) {
    inputstream is=getresources (). openrawresource (r.raw.db_vote);
    fileoutputstream fos=new fileoutputstream (databasefilename);
    byte [] buffer=new byte [8192];
    int count=0;
    while ((count=is.read (buffer))>0) {
     fos.write (buffer, 0, count);
    }
    fos.close ();
    is.close ();
   }
   db=sqlitedatabase.openorcreatedatabase (databasefilename, null);
   return db;
  } catch (exception e) {
   e.printstacktrace ();
  }
  return null;
}
  • Previous JS implementation method to obtain div coordinates
  • Next Simple Flask development framework for Python