我已经打电话了。 我想复制data / data / com.android.providers.telephony / databases / mmssms.db 以编程方式提交到SD卡。
我得到的错误就像 java.io.FileNotFoundException:/data/data/com.android.providers.telephony/databases/mmssms.db(Permission denied)
请帮助我....
提前感谢你......
我使用下面的代码来复制SD卡中的数据库 “ 试试{
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();
}`
答案 0 :(得分:0)
您正在尝试从其他应用程序复制数据库。这不被允许。即使您的手机已植根,您的应用程序也未获得root权限。
String currentDBPath = "/data/com.android.providers.telephony/databases/mmssms.db";
您需要先授予root权限,然后使用shell命令复制文件,如下所示(cp /data/..../xxx.db /sdcard/xxx.db)
Read command output inside su process
只需使用此帖子中的方法并将shell命令更改为...
stdin.writeBytes("cp /data/data/com.android.providers.telephony/databases/mmssms.db /sdcard/\n"); // \n executes the command