From aa3f17fb51bc479883520a14d76b00c8f7fc0a9a Mon Sep 17 00:00:00 2001
From: name321467 <210744682+name321467@users.noreply.github.com>
Date: Mon, 25 May 2026 01:46:39 +0000
Subject: [PATCH] Add share log action (#5682)
Add a new "Share log" menu item in Logcat.The action creates a temporary .txt file from the current log output and opens the Android share sheet, allowing users to save or send logs to other apps.
---
.../java/com/v2ray/ang/ui/LogcatActivity.kt | 61 +++++++++++++++++++
V2rayNG/app/src/main/res/menu/menu_logcat.xml | 5 ++
.../app/src/main/res/values-ar/strings.xml | 1 +
.../app/src/main/res/values-bn/strings.xml | 1 +
.../src/main/res/values-bqi-rIR/strings.xml | 1 +
.../app/src/main/res/values-fa/strings.xml | 1 +
.../app/src/main/res/values-ru/strings.xml | 1 +
.../app/src/main/res/values-vi/strings.xml | 1 +
.../src/main/res/values-zh-rCN/strings.xml | 1 +
.../src/main/res/values-zh-rTW/strings.xml | 1 +
V2rayNG/app/src/main/res/values/strings.xml | 1 +
11 files changed, 75 insertions(+)
diff --git a/V2rayNG/app/src/main/java/com/v2ray/ang/ui/LogcatActivity.kt b/V2rayNG/app/src/main/java/com/v2ray/ang/ui/LogcatActivity.kt
index e23980c8..879d566d 100644
--- a/V2rayNG/app/src/main/java/com/v2ray/ang/ui/LogcatActivity.kt
+++ b/V2rayNG/app/src/main/java/com/v2ray/ang/ui/LogcatActivity.kt
@@ -1,6 +1,8 @@
package com.v2ray.ang.ui
import android.annotation.SuppressLint
+import android.content.ClipData
+import android.content.Intent
import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
@@ -18,6 +20,11 @@ import com.v2ray.ang.viewmodel.LogcatViewModel
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
+import androidx.core.content.FileProvider
+import java.io.File
+import java.text.SimpleDateFormat
+import java.util.Date
+import java.util.Locale
class LogcatActivity : BaseActivity(), SwipeRefreshLayout.OnRefreshListener {
private val binding by lazy { ActivityLogcatBinding.inflate(layoutInflater) }
@@ -45,6 +52,55 @@ class LogcatActivity : BaseActivity(), SwipeRefreshLayout.OnRefreshListener {
return true
}
+ private fun shareLogcat() {
+ lifecycleScope.launch(Dispatchers.IO) {
+ val logText = viewModel.getAll().joinToString("\n")
+
+ val result = try {
+ val shareDir = File(cacheDir, "shared_logs").apply {
+ mkdirs()
+ }
+
+ shareDir.listFiles()?.forEach { it.delete() }
+
+ val timestamp = SimpleDateFormat("yyyy-MM-dd_HH-mm-ss", Locale.US).format(Date())
+ val logFile = File(shareDir, "v2rayNG_logcat_$timestamp.txt")
+ logFile.writeText(logText, Charsets.UTF_8)
+
+ val uri = FileProvider.getUriForFile(
+ this@LogcatActivity,
+ "${packageName}.cache",
+ logFile
+ )
+
+ uri to logFile.name
+ } catch (e: Exception) {
+ withContext(Dispatchers.Main) {
+ toast(e.localizedMessage ?: e.toString())
+ }
+ return@launch
+ }
+
+ withContext(Dispatchers.Main) {
+ val shareIntent = Intent(Intent.ACTION_SEND).apply {
+ type = "text/plain"
+ putExtra(Intent.EXTRA_STREAM, result.first)
+ putExtra(Intent.EXTRA_SUBJECT, result.second)
+ putExtra(Intent.EXTRA_TITLE, result.second)
+ addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
+ clipData = ClipData.newUri(contentResolver, result.second, result.first)
+ }
+
+ startActivity(
+ Intent.createChooser(
+ shareIntent,
+ getString(R.string.logcat_share)
+ )
+ )
+ }
+ }
+ }
+
override fun onCreateOptionsMenu(menu: Menu): Boolean {
menuInflater.inflate(R.menu.menu_logcat, menu)
@@ -78,6 +134,11 @@ class LogcatActivity : BaseActivity(), SwipeRefreshLayout.OnRefreshListener {
true
}
+ R.id.share_all -> {
+ shareLogcat()
+ true
+ }
+
R.id.clear_all -> {
lifecycleScope.launch(Dispatchers.IO) {
viewModel.clearLogcat()
diff --git a/V2rayNG/app/src/main/res/menu/menu_logcat.xml b/V2rayNG/app/src/main/res/menu/menu_logcat.xml
index 14911e57..9dec2dd0 100644
--- a/V2rayNG/app/src/main/res/menu/menu_logcat.xml
+++ b/V2rayNG/app/src/main/res/menu/menu_logcat.xml
@@ -17,4 +17,9 @@
android:icon="@drawable/ic_copy"
android:title="@string/logcat_copy"
app:showAsAction="ifRoom" />
+
\ No newline at end of file
diff --git a/V2rayNG/app/src/main/res/values-ar/strings.xml b/V2rayNG/app/src/main/res/values-ar/strings.xml
index 646a009a..2c4fafde 100644
--- a/V2rayNG/app/src/main/res/values-ar/strings.xml
+++ b/V2rayNG/app/src/main/res/values-ar/strings.xml
@@ -286,6 +286,7 @@
Logcat
نسخ
مسح
+ مشاركة السجل
إعادة تشغيل الخدمة
حذف جميع الإعدادات (قبل أول خطوة)
حذف الإعدادات المكررة (2)
diff --git a/V2rayNG/app/src/main/res/values-bn/strings.xml b/V2rayNG/app/src/main/res/values-bn/strings.xml
index 310ef977..5db4c69c 100644
--- a/V2rayNG/app/src/main/res/values-bn/strings.xml
+++ b/V2rayNG/app/src/main/res/values-bn/strings.xml
@@ -286,6 +286,7 @@
লগক্যাট
কপি করুন
স্পষ্ট করুন
+ লগ শেয়ার করুন
সার্ভিস পুনরায় চালু করুন
সব কনফিগারেশন মুছে ফেলুন
ডুপ্লিকেট কনফিগারেশন মুছে ফেলুন
diff --git a/V2rayNG/app/src/main/res/values-bqi-rIR/strings.xml b/V2rayNG/app/src/main/res/values-bqi-rIR/strings.xml
index c06421a1..4d6eaa8d 100644
--- a/V2rayNG/app/src/main/res/values-bqi-rIR/strings.xml
+++ b/V2rayNG/app/src/main/res/values-bqi-rIR/strings.xml
@@ -286,6 +286,7 @@
گوزارشا
لف گیری
روفتن
+ Share log
ره وندن دووارته خدمات
پاک کردن پوی کانفیگا بونکۊ سکویی
پاک کردن کانفیگا تکراری بونکۊ سکویی
diff --git a/V2rayNG/app/src/main/res/values-fa/strings.xml b/V2rayNG/app/src/main/res/values-fa/strings.xml
index 86af4ce7..d3e71d42 100644
--- a/V2rayNG/app/src/main/res/values-fa/strings.xml
+++ b/V2rayNG/app/src/main/res/values-fa/strings.xml
@@ -283,6 +283,7 @@
گزارشات
کپی
پاک کردن
+ اشتراکگذاری گزارش
راهاندازی مجدد خدمات
حذف تمام کانفیگ های گروه فعلی
حذف کانفیگ های تکراری گروه فعلی
diff --git a/V2rayNG/app/src/main/res/values-ru/strings.xml b/V2rayNG/app/src/main/res/values-ru/strings.xml
index 51a96571..e6f77504 100644
--- a/V2rayNG/app/src/main/res/values-ru/strings.xml
+++ b/V2rayNG/app/src/main/res/values-ru/strings.xml
@@ -291,6 +291,7 @@
Журнал
Копировать
Очистить
+ Поделиться логом
Перезапуск службы
Удалить профили
Удалить дубликаты профилей
diff --git a/V2rayNG/app/src/main/res/values-vi/strings.xml b/V2rayNG/app/src/main/res/values-vi/strings.xml
index bd3fadd6..efb79ece 100644
--- a/V2rayNG/app/src/main/res/values-vi/strings.xml
+++ b/V2rayNG/app/src/main/res/values-vi/strings.xml
@@ -286,6 +286,7 @@
Logcat
Sao chép
Xoá
+ Chia sẻ nhật ký
Khởi động lại dịch vụ lõi
Xoá tất cả cấu hình
Xoá cấu hình trùng lặp
diff --git a/V2rayNG/app/src/main/res/values-zh-rCN/strings.xml b/V2rayNG/app/src/main/res/values-zh-rCN/strings.xml
index 2c4543cd..7bac4db8 100644
--- a/V2rayNG/app/src/main/res/values-zh-rCN/strings.xml
+++ b/V2rayNG/app/src/main/res/values-zh-rCN/strings.xml
@@ -286,6 +286,7 @@
Logcat
复制
清除
+ 分享日志
服务重启
删除配置
删除重复配置
diff --git a/V2rayNG/app/src/main/res/values-zh-rTW/strings.xml b/V2rayNG/app/src/main/res/values-zh-rTW/strings.xml
index 9dd11b11..6c8727e4 100644
--- a/V2rayNG/app/src/main/res/values-zh-rTW/strings.xml
+++ b/V2rayNG/app/src/main/res/values-zh-rTW/strings.xml
@@ -285,6 +285,7 @@
Logcat
複製
清除
+ 分享日誌
重啟服務
刪除設定
刪除重複設定
diff --git a/V2rayNG/app/src/main/res/values/strings.xml b/V2rayNG/app/src/main/res/values/strings.xml
index d8c7ca37..8e9584e4 100644
--- a/V2rayNG/app/src/main/res/values/strings.xml
+++ b/V2rayNG/app/src/main/res/values/strings.xml
@@ -293,6 +293,7 @@
Logcat
Copy
Clear
+ Share log
Service restart
Delete config
Delete duplicate config