Access数据库没有生根 [英] Access database without rooting

查看:137
本文介绍了Access数据库没有生根的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经徒劳地​​寻找广泛找到没有生根我的Andr​​oid手机来访问数据库的方法。我不想用AVD,因为它是非常缓慢的。但为了看到我在做什么,我需要从PC或手机上访问我的应用.db文件以某种方式。

I've already vainly searched extensively to find a method to access db without rooting my android phone. I don't want to use AVD as it's very slow. But in order to see what I'm doing I need to access my app .db file from PC or phone in someway.

/data/data//databases/.db没有真正的设备。

/data/data//databases/.db doesn't work for real devices.

所以,请建议我一些方法,通过它我可以看到我的数据库。

So, please suggest me some method by which I can see my database.

推荐答案

只需添加code在特定的情况下应用程序将数据库拷贝到SD卡,这将是乌拉圭回合的DB /数据副本而不是实际的DB 。从SD卡可以随时访问数据库。
这是围绕工作,但它为我工作。

Just add code in your application on specific event it will copy the DB into SD card, it will be copy of ur DB/data not actual DB. From SD card you can always access the DB. this is the work around but it works for me.

下面是code

    try {
        File sd = Environment.getExternalStorageDirectory();
        File data = Environment.getDataDirectory();
        if (sd.canWrite()) {
            String currentDBPath = "data/"+sPackageName+"/databases/"+sDBName;
            String backupDBPath = "/.appname-external-data-cache/"+sDBName; //"{database name}";
            File dir = new File(sd,backupDBPath.replace(sDBName,""));
            if(dir.mkdir()) {

            }
            File currentDB = new File(data, currentDBPath);
            File backupDB = new File(sd, backupDBPath);
            if (currentDB.exists()) {
                FileChannel src = new FileInputStream(currentDB).getChannel();
                FileChannel dst = new FileOutputStream(backupDB).getChannel();
                dst.transferFrom(src, 0, src.size());
                src.close();
                dst.close();
            }
        } 

   } catch (Exception e) {

    }

这篇关于Access数据库没有生根的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆