From cee7103efe5d8e9dcc6ada55b0f1ee65e476eb21 Mon Sep 17 00:00:00 2001 From: Kieran Date: Fri, 6 Sep 2024 17:02:57 +0100 Subject: [PATCH] Add ability to send log files --- app/src/main/AndroidManifest.xml | 9 +++ .../com/openipc/pixelpilot/VideoActivity.java | 62 +++++++++++++++++++ app/src/main/res/xml/file_paths.xml | 4 ++ 3 files changed, 75 insertions(+) create mode 100644 app/src/main/res/xml/file_paths.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index f077b89..d699862 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -22,6 +22,15 @@ android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true"> + + + { + try { + Process process = Runtime.getRuntime().exec("logcat -d"); + BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream())); + + String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); + File logFile = new File(getExternalFilesDir(null), "pixelpilot_log_" + timeStamp + ".txt"); + FileWriter fileWriter = new FileWriter(logFile); + + String versionName = ""; + long versionCode = 0; + + try { + PackageInfo packageInfo = getPackageManager().getPackageInfo(getPackageName(), 0); + versionName = packageInfo.versionName; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { + versionCode = packageInfo.getLongVersionCode(); + } else { + versionCode = packageInfo.versionCode; + } + } catch (PackageManager.NameNotFoundException e) { + } + + fileWriter.append("Device Model: " + Build.MODEL + "\n" + + "Manufacturer: " + Build.MANUFACTURER + "\n" + + "OS Version: " + Build.VERSION.RELEASE + "\n" + + "SDK Version: " + Build.VERSION.SDK_INT + "\n" + + "App Version Name: " + versionName + "\n" + + "App Version Code: " + versionCode + "\n"); + + String line; + + while ((line = bufferedReader.readLine()) != null) { + fileWriter.append(line).append("\n"); + } + fileWriter.flush(); + fileWriter.close(); + Intent sendIntent = new Intent(); + sendIntent.setAction(Intent.ACTION_SEND); + Uri fileUri = FileProvider.getUriForFile(this, getPackageName() + ".provider", logFile); + sendIntent.putExtra(Intent.EXTRA_STREAM, fileUri); + sendIntent.setType("text/plain"); + sendIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); + Intent shareIntent = Intent.createChooser(sendIntent, null); + startActivity(shareIntent); + + } catch (IOException e) { + Log.e(TAG, "ShareLog: ", e); + } + return true; + }); + popup.show(); }); diff --git a/app/src/main/res/xml/file_paths.xml b/app/src/main/res/xml/file_paths.xml new file mode 100644 index 0000000..d6a3ac0 --- /dev/null +++ b/app/src/main/res/xml/file_paths.xml @@ -0,0 +1,4 @@ + + + +