0

I have rooted phone. I want to copy data/data/com.android.providers.telephony/databases/mmssms.db file to sd card programatically.

I am getting error like java.io.FileNotFoundException: /data/data/com.android.providers.telephony/databases/mmssms.db (Permission denied)

Please help me....

Thanking you in advance...

I am using below code to copy database in sd card ' try {

            File sd = Environment.getExternalStorageDirectory();
            String path = Environment.getDataDirectory().getAbsolutePath();
            File data = Environment.getDataDirectory();
            String currentDBPath = "/data/com.android.providers.telephony/databases/mmssms.db";
            String backupDBPath = "/bkup/mmssms.db";
            File currentDB = new File(data, currentDBPath);
            File backupDB = new File(sd, backupDBPath);
            // Local database
            InputStream input = new FileInputStream(currentDB);

            // Path to the external backup
            OutputStream output = new FileOutputStream(backupDB);

            // transfer bytes from the Input File to the Output File
            byte[] buffer = new byte[1024];
            int length;
            while ((length = input.read(buffer))>0) {
                output.write(buffer, 0, length);
            }

            output.flush();
            output.close();
            input.close();
    } catch (Exception e) {
        // TODO: handle exception
        Toast.makeText(this, e.getMessage().toString(), Toast.LENGTH_LONG).show();
    }`
Amol Benare
  • 59
  • 1
  • 2
  • 8

1 Answers1

0

You're trying to copy the database from other application. It's not allowed. Even your phone is rooted, your application is not granted the root permission yet.

String currentDBPath = "/data/com.android.providers.telephony/databases/mmssms.db";

You need to grant the root permission first, and use the shell commands to copy file, like this (cp /data/..../xxx.db /sdcard/xxx.db)

Read command output inside su process

Just use the method in this post and change the shell command to ...

stdin.writeBytes("cp /data/data/com.android.providers.telephony/databases/mmssms.db /sdcard/\n"); // \n executes the command
Community
  • 1
  • 1
dong221
  • 3,390
  • 6
  • 29
  • 31
  • Thanks for your quick response dong. I am newbie in this section so Can I do this programatically? The path I have mentioned is actual path in my mobile for sms db. – Amol Benare Feb 24 '12 at 05:20
  • Just did it myself :D , the method is as above. – dong221 Feb 24 '12 at 06:00
  • yes!!!!!! Thanks buddy... You are gr8. I got it working... Thanks for the help.... – Amol Benare Feb 24 '12 at 06:16
  • hello friends I am restoring same database to the /data/data/com.android.providers.telephony/databases/mmssms.db folder . Restore completed successfully but if I open messaging app it shows me error like **the application messaging process.com.android.mms has stopped unexpectedly** and force close please help me – Amol Benare Feb 24 '12 at 09:22