How to copy your own database from an Android phone

Source: Internet
Author: User
Tags sqlite database

============ Problem Description ============


Write your own apk, installed on the Android phone, the program will be run to create a SQLite database;
With eclipse, you can see the location of the database, I put the phone into the computer, after the USB connection, but not in the phone to find the database file (APK is absolutely installed on the SD card), someone said to have root permissions. Do not know how to achieve, if you want to write a program to achieve, please master pointing ideas, list the relevant key functions, thank you

============ Solution 1============


Their own application to copy their own database, without root, direct file copy on the line, probably as follows:
File F = new file ("/data/data/application's package name/databases/database name"); Like "/data/data/com.hello/databases/test.db."
String Sdcardpath = Environment.getexternalstoragedirectory (). GetAbsolutePath ();
File o = new file (sdcardpath+ "cp.db"); Destination address on the SDcard
if (f.exists ()) {
FileChannel Outf;
try {
Outf = new FileOutputStream (o). Getchannel ();
New FileInputStream (f). Getchannel (). TransferTo (0, F.length (), OUTF);
} catch (FileNotFoundException e) {
E.printstacktrace ();
} catch (IOException e) {
E.printstacktrace ();
}
Toast.maketext (Mainpage.this, "done", Toast.length_short). Show ();
}

How to copy your own database from an Android phone

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.