简体   繁体   English

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

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

In the old eclipse IDE there was an option to install sqlite browser and view the database in the ide itself without downloading and saving it to our system. 在旧的eclipse IDE中,可以选择安装sqlite浏览器并在ide本身中查看数据库,而无需下载并将其保存到我们的系统中。

In the new android studio there is an option call device explorer where you can go to data/data//databases/yourdb.db 在新的Android Studio中,有一个选项调用设备资源管理器,您可以在其中访问data / data // databases / yourdb.db

but when you click on it you will be provided with open, save as, delete, synchronize and copypath 但是当您单击它时,将为您提供打开,另存为,删除,同步和复制路径

when i click on open 当我点击打开

在此处输入图片说明

but couldn't find anything to load the db in that options. 但在该选项中找不到任何可加载数据库的内容。 I scrolled to end i checked. 我滚动到结束我检查。

Please help me in finding out what app from that selection should i use to view the db if it have any. 请帮助我从该选择中找出应该使用哪个应用程序查看数据库(如果有)。

Or can i install some plugins to android studio and view the db directly from devive explorer 或者我可以将一些插件安装到android studio并直接从devive资源管理器中查看数据库

One more question is there is no Tools/Android section in new Android studio to view android device monitor where can i find android device monitor in new android studio 另一个问题是,新的Android Studio中没有“工具/ Android”部分,无法查看Android设备监视器 ,在哪里可以找到新的Android Studio中的Android设备监视器?

Please help 请帮忙

In AS 3.1.2 there is option to right side as 'Device File Explorer' click on it then select data\\data\\'package name'\\database\\ here you will get your database file. 在AS 3.1.2中,有一个右侧选项,单击“设备文件资源管理器”,然后选择data \\ data \\'package name'\\ database \\,您将在其中获取数据库文件。 Save it on any drive location. 将其保存在任何驱动器位置。 To view content install 'DB Browser for SQLite' there is option open database 要查看内容,请安装“ DB Browser for SQLite”,其中有打开数据库的选项

As of now there is no option to open db in Android Studio however you can try these options : 到目前为止,尚无在Android Studio打开数据库的选项,但是您可以尝试以下选项:

I believe you are trying to open db in Android studio itself just to save time, if this is the case you can use this Python script to copy db into your local machine and then open in SQLite DB browser . 我相信您正在尝试在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")

Execution : Set default variables like packageName & dbName in script and then 执行:在脚本中设置默认变量,例如packageNamedbName ,然后

python Copydbfileandroid.py -d

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

相关问题 如何在Android Studio(3.0.1)/设备文件资源管理器中打开sqlite文件 - How to open a sqlite file in Android Studio (3.0.1) / Device File Explorer 如何在没有Android Studio的情况下启动Android设备文件资源管理器? - How to start Android Device File Explorer without Android Studio? Android Studio的SQLite数据库中的文件资源管理器 - File explorer in sqlite database of android studio 在 Android Studio 中查看设备上的 SQLite 数据库 - View SQLite database on device in Android Studio 为什么SQLite Database无法在android studio的文件资源管理器中显示? - Why SQLite Database not showing in File Explorer in android studio? 如何从android studio中的recycler视图将数据添加到SQLite数据库中 - How to add data into SQLite database from recycler view in android studio android 工作室的设备文件资源管理器中缺少数据库文件夹 - database folder is missing in device file explorer in android studio 从Android设备提取Sqlite数据库文件 - Extracting Sqlite Database file from Android Device 如何更改默认设置以在 Android Studio 的设备文件资源管理器中以文本形式打开数据库文件? - How to change the default set to open database files as text in Device File Explorer in Android Studio? 如何从Android设备下载SQLite数据库? - How to download an SQLite database from an Android device?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM