0

I need to get my developed Android app logs. I seen we can do it using adb and android studio, but i want to save logs into device memory for app event track as i can not use PC all time. I am using log.i, log.d, log.e in my coding.

I searched on internet and found some methods but none of them able to create all events logs into file while using android studio logcat i am getting all the event logs of my App.

AndroidManifes.xml:

<uses-permission android:name="android.permission.READ_LOGS"
    tools:ignore="ProtectedPermissions" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

Main.java

onCreate(){
if (isExternalStorageWritable()) {

    File appDirectory = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), "TP3");
    Log.d("dbKaps", "App directory created ");
    File logDirectory = new File(appDirectory + "/logs");
    Log.d("dbKaps", "Log directory created ");
    File logFile = new File(logDirectory, "logcat_" + System.currentTimeMillis() + ".txt");
    Log.d("dbKaps", "logcat TXT file created ");

    // create app folder
    if (!appDirectory.exists()) {
        appDirectory.mkdir();
        Log.d("dbKaps", "App Directory already exists ");
    }

    // create log folder
    if (!logDirectory.exists()) {
        logDirectory.mkdir();
        Log.d("dbKaps", "Log Directory already exists ");
    }

    // clear the previous logcat and then write the new one to the file
    try {
        Process process = Runtime.getRuntime().exec("logcat -c");
        process = Runtime.getRuntime().exec("logcat -f " + logFile);
        Log.d("dbKaps", "new logcat started ");
    } catch (IOException e) {
        e.printStackTrace();
    }



} else if (isExternalStorageReadable()) {
    // only readable
} else {
    // not accessible
}
}
public boolean isExternalStorageWritable() {
    String state = Environment.getExternalStorageState();
    if ( Environment.MEDIA_MOUNTED.equals( state ) ) {
        Log.i("dbKaps", "Storage writable permission granted ");
        return true;
    }
    return false;
}
public boolean isExternalStorageReadable() {
    String state = Environment.getExternalStorageState();
    if ( Environment.MEDIA_MOUNTED.equals( state ) ||
            Environment.MEDIA_MOUNTED_READ_ONLY.equals( state ) ) {
        Log.i("dbKaps", "Storage readable permission granted only ");
        return true;
    }
    return false;
}

OUTPUT:

I am getting limited event logs into lofile.

08-11 22:56:44.779 I/BufferQueueConsumer(30620): [](id:779c00000000,api:0,p:-1,c:30620) connect: controlledByApp=false

08-11 22:56:44.781 I/BLASTBufferQueue(30620): [ViewRootImpl[MainActivity]#0] constructor()

08-11 22:56:44.792 E/GED (30620): Failed to get GED Log Buf, err(0)

08-11 22:56:44.794 D/hw-ProcessState(30620): Binder ioctl to enable oneway spam detection failed: Invalid argument

08-11 22:56:44.814 I/BufferQueueProducer(30620): [ViewRootImpl[MainActivity]#0(BLAST Consumer)0](id:779c00000000,api:1,p:30620,c:30620) connect: api=1 producerControlledByApp=true

08-11 22:56:44.824 E/ion (30620): ioctl c0044901 failed with code -1: Invalid argument

08-11 22:56:44.948 E/OpenGLRenderer(30620): fbcNotifyFrameComplete error: undefined symbol: fbcNotifyFrameComplete

08-11 22:56:44.948 E/OpenGLRenderer(30620): fbcNotifyNoRender error: undefined symbol: fbcNotifyNoRender

Kay Bee
  • 3
  • 2

0 Answers0