Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>first of all make sure you add android.permission.WRITE_EXTERNAL_STORAGE permission to your manifest file. In one my apps I used class below and it works perfectly. Try this and let me know if it works.</p> <pre><code>public class ImpotDatabaseFileTask extends AsyncTask&lt;String, Void, Boolean&gt; { ProgressDialog dialog; private Context con; boolean success = false; public ImpotDatabaseFileTask(Context con) { this.con = con; dialog = new ProgressDialog(con); this.dialog.setMessage("Importing database..."); execute(null); } @Override protected Boolean doInBackground(String... params) { try { OutputStream myOutput; File destination = new File(Environment.getDataDirectory() + "//data//&lt;package name&gt;//databases//database_name.db"); // Set the folder on the SDcard File dbFile = new File(Environment.getExternalStorageDirectory(), "//&lt;custom folder&gt;//&lt;database_name&gt;.db"); if (dbFile.exists()) { copyFile(dbFile, destination); success = true; } } catch (FileNotFoundException e) { // Toast.makeText(Settings.this, // "Restore unsuccessful! File not found! Directory does not exist?", // Toast.LENGTH_LONG).show(); // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { Toast.makeText(con, "Restore unsuccessful!", Toast.LENGTH_SHORT) .show(); // TODO Auto-generated catch block e.printStackTrace(); } return null; } void copyFile(File src, File dst) throws IOException { FileChannel inChannel = new FileInputStream(src).getChannel(); FileChannel outChannel = new FileOutputStream(dst).getChannel(); try { inChannel.transferTo(0, inChannel.size(), outChannel); } finally { if (inChannel != null) inChannel.close(); if (outChannel != null) outChannel.close(); } } @Override protected void onPostExecute(Boolean result) { if (this.dialog.isShowing()) { this.dialog.dismiss(); } if (success) { Toast.makeText(con, "Restore successful!", Toast.LENGTH_SHORT) .show(); } else { Toast.makeText(con, "Restore failed", Toast.LENGTH_SHORT).show(); } super.onPostExecute(result); } </code></pre> <p>}</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload