繁体   English   中英

如何在Android Studio中从设备文件资源管理器查看sqlite数据库而不将其保存到系统

[英]How to view sqlite database from device file explorer in android studio without saving it to system

在旧的eclipse IDE中,可以选择安装sqlite浏览器并在ide本身中查看数据库,而无需下载并将其保存到我们的系统中。

在新的Android Studio中,有一个选项调用设备资源管理器,您可以在其中访问data / data // databases / yourdb.db

但是当您单击它时,将为您提供打开,另存为,删除,同步和复制路径

当我点击打开

在此处输入图片说明

但在该选项中找不到任何可加载数据库的内容。 我滚动到结束我检查。

请帮助我从该选择中找出应该使用哪个应用程序查看数据库(如果有)。

或者我可以将一些插件安装到android studio并直接从devive资源管理器中查看数据库

另一个问题是,新的Android Studio中没有“工具/ Android”部分,无法查看Android设备监视器 ,在哪里可以找到新的Android Studio中的Android设备监视器?

请帮忙

在AS 3.1.2中,有一个右侧选项,单击“设备文件资源管理器”,然后选择data \\ data \\'package name'\\ database \\,您将在其中获取数据库文件。 将其保存在任何驱动器位置。 要查看内容,请安装“ DB Browser for SQLite”,其中有打开数据库的选项

到目前为止,尚无在Android Studio打开数据库的选项,但是您可以尝试以下选项:

我相信您正在尝试在Android studio本身中打开db以节省时间,如果是这种情况,则可以使用 Python脚本将db复制到本地计算机中,然后在SQLite DB浏览器中打开。

import sys
import subprocess
import re


#/
# Created by @nieldeokar on 25/05/2018.
#/

# 1. Python script which will copy database file of debuggable apps from the android device to your computer using ADB.
# 2. This script ask for PackageName and DatabaseName at runtime.
# 3. You can make it static by passing -d at as command line argument while running script and setting defaults in following way.
# 4. Edit script and change the values of varialbe packageName and dbName to debuggable app package name and database name then
# run script as : python Copydbfileandroid.py -d 

useDefaults = False


def checkIfPackageInstalled(strSelectedDevice) :

    packageName = 'com.nileshdeokar.healthapp.debug'
    dbName = 'healthapp.db'


    if not useDefaults : 
        print('Please enter package name : ')
        packageName = raw_input()

    packageString = 'package:'+packageName

    try:
        adbCheckIfPackageInstalledOutput = subprocess.check_output('adb -s ' + strSelectedDevice + ' shell pm list packages | grep -x '+ packageString, shell=True)
    except subprocess.CalledProcessError as e:
                print "Package not found"
                return


    if packageString.strip() == adbCheckIfPackageInstalledOutput.strip() : 
        if not useDefaults : 
            print('Please enter db name : ')
            dbName = raw_input()

        adbCopyDbString = 'adb -s '+strSelectedDevice + ' -d shell \"run-as '+packageName+' cat /data/data/'+packageName+'/databases/'+ dbName +'\" > '+dbName

        try:
            copyDbOp = subprocess.check_output(adbCopyDbString,shell=True)
        except subprocess.CalledProcessError as e:
                return

        if "is not debuggable" in copyDbOp :
            print packageString + 'is nto debuggable'

        if copyDbOp.strip() == "":
            print 'Successfully copied '+dbName + ' in current directory'

    else :
        print 'Package is not installed on the device'



defaultString = "-d"
if len(sys.argv[1:]) > 0 and sys.argv[1] == defaultString :
        useDefaults = True

listDevicesOutput = subprocess.check_output("adb devices", shell=True)
listDevicesOutput = listDevicesOutput.replace("List of devices attached"," ").replace("\n","").replace("\t","").replace("\n\n","")

numberofDevices = len(re.findall(r'device+', listDevicesOutput))

connectedDevicesArray = listDevicesOutput.split("device")   
del connectedDevicesArray[-1] 


strSelectedDevice = ''
if(numberofDevices > 1) :
    print('Please select the device : \n'),

    for idx, device in enumerate(connectedDevicesArray):
        print idx+1,device

    selectedDevice = raw_input()

    if selectedDevice.isdigit() :
        intSelected = int(selectedDevice)
        if 1 <= intSelected <= len(connectedDevicesArray) :
            print 'Selected device is : ',connectedDevicesArray[intSelected-1]
            checkIfPackageInstalled(connectedDevicesArray[intSelected-1])
        else :
            print 'Please select in range'
    else : 
        print 'Not valid input'

elif numberofDevices == 1 :
    checkIfPackageInstalled(connectedDevicesArray[0])
elif numberofDevices == 0 :
    print("No device is attached")

执行:在脚本中设置默认变量,例如packageNamedbName ,然后

python Copydbfileandroid.py -d

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM