Search code examples
javaandroidandroid-studioexport-to-csv

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


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 !


Solution

  • 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: How can I connect to Android with ADB over TCP?