我们为客户端开发了安卓应用程序和门户网站,sqllite
db安装在安卓应用程序中。我想做离线同步,为了做到这一点,我是连接安卓设备到PC通过USB
。是否可以从门户网站访问安装在android设备中的sqllite db?
我真的很感激你的回答。
发布于 2016-07-28 07:54:58
我认为您不能直接从usb访问,因为数据库将存储在专用内存中,而不是sdcard中,但是您可以通过应用程序中的代码导出数据库(只是为了查看目的),并将文件上传到服务器。
public class ExportDB {
final static String SAMPLE_DB_NAME = "yourdatabase";
public static void exportDB(Context context){
File sd = Environment.getExternalStorageDirectory();
File data = Environment.getDataDirectory();
FileChannel source=null;
FileChannel destination=null;
String currentDBPath = "/data/"+ "your.package.name" +"/databases/"+SAMPLE_DB_NAME;
String backupDBPath = SAMPLE_DB_NAME;
File currentDB = new File(data, currentDBPath);
File backupDB = new File(sd, backupDBPath);
try {
source = new FileInputStream(currentDB).getChannel();
destination = new FileOutputStream(backupDB).getChannel();
destination.transferFrom(source, 0, source.size());
source.close();
destination.close();
Toast.makeText(context, "DB Exported!", Toast.LENGTH_LONG).show();
} catch(IOException e) {
e.printStackTrace();
}
}
}
https://stackoverflow.com/questions/38630081
复制相似问题