In Unity, create a class:
public class LogsHelper { private static AndroidJavaObject m_Activity; private static AndroidJavaObject m_Logger; private static AndroidJavaObject GetActivity() { if (m_Activity == null) { var unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); m_Activity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity"); } return m_Activity; } private static AndroidJavaObject GetLogsHelper() { return m_Logger ?? (m_Logger = new AndroidJavaObject("com.test.LogsSender")); } public static void SendLogs() { GetLogsHelper().Call("sendLogs", GetActivity()); } }
Java plugin class:
package com.test; import android.app.Activity; import android.content.Intent; import android.util.Log; import java.io.BufferedReader; import java.io.InputStreamReader; public class LogsSender { public void sendLogs(Activity activity) { Log.d("unity", "sendLogs" ); int pid = android.os.Process.myPid(); try { String command = String.format("logcat -d -v threadtime *:*"); Process process = Runtime.getRuntime().exec(command); BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream())); StringBuilder result = new StringBuilder(); String currentLine = null; while ((currentLine = reader.readLine()) != null) { if (currentLine != null && currentLine.contains(String.valueOf(pid))) { result.append(currentLine); result.append("\n"); } } Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); emailIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); emailIntent.setType("vnd.android.cursor.item/email"); emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] {"support@kek.com"}); emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Logs"); emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, result.toString()); activity.startActivity(Intent.createChooser(emailIntent, "Send mail using...")); } catch (Exception e) { e.printStackTrace(); } } }
You may need <uses-permission android:name="android.permission.READ_LOGS" /> .
In Unity, call LogsHelper.SendLogs() . After that, the user will see a window with a choice of mail application. After selecting the application will open, where all the fields will be already driven in, the user needs only to click on the "Send" button. After that, the logs will be successfully sent to your email.