如何实时从Android Studio将数据导出到我的计算机?

huangapple go评论84阅读模式
英文:

How can I export data in real time from Android Studio to my computer

问题

我在Android Studio中使用Java创建了一个Android应用程序,需要导出一些数据进行验证。我想要将一个2维整数数组保存在我电脑或手机上的**.csv或.txt**文件中(我的手机没有SD卡槽)。

你有什么想法吗?

进一步说,我想实时将数据导出到我的电脑,并使用Python或Bash绘制这个二维数组。这可行吗?

非常感谢!

英文:

I created an android application in java in android studio and I need to export some data for validation purpose. I would like to save a 2 dimensiohs integer array in a .csv or .txt file in my computer or in my phone when I am running the application (I don't Have SD card slot in my phone).

Do you have any Idea ?

To go further, I will love to export the data in real time to my computer and to plot the 2 dimension array with python or Bash.. Is it possible ?

Thanks a lot !

答案1

得分: 0

你可以在控制台中运行 adb logcat 并以任何方便的方式解析实时数据:https://developer.android.com/studio/command-line/logcat

示例(Windows PowerShell):

& $ENV:LOCALAPPDATA\Android\Sdk\platform-tools\adb.exe logcat -s MyTag

在应用程序中(Java):

Log.d("MyTag", "My debug data");

在Python中获取实时logcat数据(Windows):

import os, subprocess
cmd = os.getenv("LOCALAPPDATA") + r"\Android\Sdk\platform-tools\adb.exe logcat -s MyTag"
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, bufsize=1)
for line in iter(p.stdout.readline, b""):
    print(line)
p.stdout.close()
p.wait()

提示: 你还可以通过本地Wi-Fi网络进行调试,而不需要将设备通过电缆连接到电脑上:https://stackoverflow.com/questions/2604727/how-can-i-connect-to-android-with-adb-over-tcp

英文:

You can run adb logcat in console and parse live data in any way convenient for you: https://developer.android.com/studio/command-line/logcat

Example (Windows PowerShell):

 & $ENV:LOCALAPPDATA\Android\Sdk\platform-tools\adb.exe logcat -s MyTag

In app (Java):

Log.d("MyTag", "My debug data");

Getting live logcat data in Python (Windows):

import os, subprocess
cmd = os.getenv("LOCALAPPDATA") + r"\Android\Sdk\platform-tools\adb.exe logcat -s MyTag"
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, bufsize=1)
for line in iter(p.stdout.readline, b""):
    print(line)
p.stdout.close()
p.wait()

Tip: you can also run debugging via local Wi-Fi network without connecting the device with a cable to your PC: https://stackoverflow.com/questions/2604727/how-can-i-connect-to-android-with-adb-over-tcp

huangapple
  • 本文由 发表于 2020年8月13日 21:41:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/63396508.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定