mirror of
https://github.com/KitsunePie/AppErrorsTracking.git
synced 2025-09-01 08:45:16 +08:00
feat: support share errors stacktrace with file
This commit is contained in:
@@ -117,5 +117,15 @@
|
|||||||
<action android:name="android.service.quicksettings.action.QS_TILE" />
|
<action android:name="android.service.quicksettings.action.QS_TILE" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</service>
|
</service>
|
||||||
|
|
||||||
|
<provider
|
||||||
|
android:name="androidx.core.content.FileProvider"
|
||||||
|
android:authorities="${applicationId}.provider"
|
||||||
|
android:exported="false"
|
||||||
|
android:grantUriPermissions="true">
|
||||||
|
<meta-data
|
||||||
|
android:name="android.support.FILE_PROVIDER_PATHS"
|
||||||
|
android:resource="@xml/file_paths" />
|
||||||
|
</provider>
|
||||||
</application>
|
</application>
|
||||||
</manifest>
|
</manifest>
|
@@ -59,6 +59,9 @@ object ConfigData {
|
|||||||
/** 禁止异常堆栈内容自动换行 */
|
/** 禁止异常堆栈内容自动换行 */
|
||||||
val DISABLE_AUTO_WRAP_ERROR_STACK_TRACE = PrefsData("_disable_auto_wrap_error_stack_trace", false)
|
val DISABLE_AUTO_WRAP_ERROR_STACK_TRACE = PrefsData("_disable_auto_wrap_error_stack_trace", false)
|
||||||
|
|
||||||
|
/** 分享时使用文件 */
|
||||||
|
val SHARE_WITH_FILE = PrefsData("_share_with_file", false)
|
||||||
|
|
||||||
/** 当前实例 - [Context] or [PackageParam] */
|
/** 当前实例 - [Context] or [PackageParam] */
|
||||||
private var instance: Any? = null
|
private var instance: Any? = null
|
||||||
|
|
||||||
@@ -216,4 +219,13 @@ object ConfigData {
|
|||||||
set(value) {
|
set(value) {
|
||||||
putBoolean(ENABLE_MATERIAL3_STYLE_APP_ERRORS_DIALOG, value)
|
putBoolean(ENABLE_MATERIAL3_STYLE_APP_ERRORS_DIALOG, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否以文件方式分享
|
||||||
|
*/
|
||||||
|
var isShareWithFile
|
||||||
|
get() = getBoolean(SHARE_WITH_FILE)
|
||||||
|
set(value) {
|
||||||
|
putBoolean(SHARE_WITH_FILE, value)
|
||||||
|
}
|
||||||
}
|
}
|
@@ -27,6 +27,7 @@ import android.app.Activity
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
|
import androidx.core.content.FileProvider
|
||||||
import androidx.core.view.isGone
|
import androidx.core.view.isGone
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
import com.fankes.apperrorstracking.R
|
import com.fankes.apperrorstracking.R
|
||||||
@@ -47,6 +48,7 @@ import com.fankes.apperrorstracking.utils.factory.showDialog
|
|||||||
import com.fankes.apperrorstracking.utils.factory.toast
|
import com.fankes.apperrorstracking.utils.factory.toast
|
||||||
import com.fankes.apperrorstracking.utils.tool.StackTraceShareHelper
|
import com.fankes.apperrorstracking.utils.tool.StackTraceShareHelper
|
||||||
import com.highcapable.yukihookapi.hook.log.loggerE
|
import com.highcapable.yukihookapi.hook.log.loggerE
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
class AppErrorsDetailActivity : BaseActivity<ActivityAppErrorsDetailBinding>() {
|
class AppErrorsDetailActivity : BaseActivity<ActivityAppErrorsDetailBinding>() {
|
||||||
|
|
||||||
@@ -143,8 +145,21 @@ class AppErrorsDetailActivity : BaseActivity<ActivityAppErrorsDetailBinding>() {
|
|||||||
binding.shareIcon.setOnClickListener {
|
binding.shareIcon.setOnClickListener {
|
||||||
StackTraceShareHelper.showChoose(context = this, locale.shareErrorStack) { sDeviceBrand, sDeviceModel, sDisplay, sPackageName ->
|
StackTraceShareHelper.showChoose(context = this, locale.shareErrorStack) { sDeviceBrand, sDeviceModel, sDisplay, sPackageName ->
|
||||||
startActivity(Intent.createChooser(Intent(Intent.ACTION_SEND).apply {
|
startActivity(Intent.createChooser(Intent(Intent.ACTION_SEND).apply {
|
||||||
type = "text/plain"
|
val content = appErrorsInfo.stackOutputShareContent(sDeviceBrand, sDeviceModel, sDisplay, sPackageName)
|
||||||
putExtra(Intent.EXTRA_TEXT, appErrorsInfo.stackOutputShareContent(sDeviceBrand, sDeviceModel, sDisplay, sPackageName))
|
if (ConfigData.isShareWithFile) {
|
||||||
|
type = "application/octet-stream"
|
||||||
|
runCatching {
|
||||||
|
val file = File.createTempFile("app_errors_stacktrace_", ".log", cacheDir)
|
||||||
|
file.deleteOnExit()
|
||||||
|
file.writeText(content)
|
||||||
|
putExtra(Intent.EXTRA_STREAM, FileProvider.getUriForFile(this@AppErrorsDetailActivity, "$packageName.provider", file))
|
||||||
|
}.onFailure {
|
||||||
|
toast(msg = "Create temp file failed")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
type = "text/plain"
|
||||||
|
putExtra(Intent.EXTRA_TEXT, content)
|
||||||
|
}
|
||||||
}, locale.shareErrorStack))
|
}, locale.shareErrorStack))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -194,6 +209,7 @@ class AppErrorsDetailActivity : BaseActivity<ActivityAppErrorsDetailBinding>() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onBackPressed() {
|
override fun onBackPressed() {
|
||||||
|
super.onBackPressed()
|
||||||
intent?.removeExtra(EXTRA_APP_ERRORS_INFO)
|
intent?.removeExtra(EXTRA_APP_ERRORS_INFO)
|
||||||
finish()
|
finish()
|
||||||
}
|
}
|
||||||
|
@@ -99,6 +99,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
|||||||
binding.onlyShowErrorsInFrontSwitch.bind(ConfigData.ENABLE_ONLY_SHOW_ERRORS_IN_FRONT)
|
binding.onlyShowErrorsInFrontSwitch.bind(ConfigData.ENABLE_ONLY_SHOW_ERRORS_IN_FRONT)
|
||||||
binding.onlyShowErrorsInMainProcessSwitch.bind(ConfigData.ENABLE_ONLY_SHOW_ERRORS_IN_MAIN)
|
binding.onlyShowErrorsInMainProcessSwitch.bind(ConfigData.ENABLE_ONLY_SHOW_ERRORS_IN_MAIN)
|
||||||
binding.alwaysShowsReopenAppOptionsSwitch.bind(ConfigData.ENABLE_ALWAYS_SHOWS_REOPEN_APP_OPTIONS)
|
binding.alwaysShowsReopenAppOptionsSwitch.bind(ConfigData.ENABLE_ALWAYS_SHOWS_REOPEN_APP_OPTIONS)
|
||||||
|
binding.shareWithFile.bind(ConfigData.SHARE_WITH_FILE)
|
||||||
binding.enableAppsConfigsTemplateSwitch.bind(ConfigData.ENABLE_APP_CONFIG_TEMPLATE) {
|
binding.enableAppsConfigsTemplateSwitch.bind(ConfigData.ENABLE_APP_CONFIG_TEMPLATE) {
|
||||||
onInitialize { binding.mgrAppsConfigsTemplateButton.isVisible = it }
|
onInitialize { binding.mgrAppsConfigsTemplateButton.isVisible = it }
|
||||||
onChanged { reinitialize() }
|
onChanged { reinitialize() }
|
||||||
|
@@ -298,6 +298,30 @@
|
|||||||
android:textColor="@color/colorTextDark"
|
android:textColor="@color/colorTextDark"
|
||||||
android:textSize="12sp" />
|
android:textSize="12sp" />
|
||||||
|
|
||||||
|
<com.fankes.apperrorstracking.ui.widget.MaterialSwitch
|
||||||
|
android:id="@+id/share_with_file"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="30dp"
|
||||||
|
android:layout_marginLeft="15dp"
|
||||||
|
android:layout_marginRight="15dp"
|
||||||
|
android:layout_marginBottom="5dp"
|
||||||
|
android:text="@string/share_with_file"
|
||||||
|
android:textAllCaps="false"
|
||||||
|
android:textColor="@color/colorTextGray"
|
||||||
|
android:textSize="15sp" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginLeft="15dp"
|
||||||
|
android:layout_marginRight="15dp"
|
||||||
|
android:layout_marginBottom="10dp"
|
||||||
|
android:alpha="0.6"
|
||||||
|
android:lineSpacingExtra="6dp"
|
||||||
|
android:text="@string/share_with_file_tip"
|
||||||
|
android:textColor="@color/colorTextDark"
|
||||||
|
android:textSize="12sp" />
|
||||||
|
|
||||||
<com.fankes.apperrorstracking.ui.widget.MaterialSwitch
|
<com.fankes.apperrorstracking.ui.widget.MaterialSwitch
|
||||||
android:id="@+id/enable_apps_configs_template_switch"
|
android:id="@+id/enable_apps_configs_template_switch"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
@@ -157,4 +157,6 @@
|
|||||||
<string name="stack_trace_share_system_build_id">系统构建 ID</string>
|
<string name="stack_trace_share_system_build_id">系统构建 ID</string>
|
||||||
<string name="stack_trace_share_package_name">APP 包名</string>
|
<string name="stack_trace_share_package_name">APP 包名</string>
|
||||||
<string name="stack_trace_share_other">其它必要信息</string>
|
<string name="stack_trace_share_other">其它必要信息</string>
|
||||||
|
<string name="share_with_file">以文件方式分享异常堆栈</string>
|
||||||
|
<string name="share_with_file_tip">使用文件的方式代替文本分享异常堆栈</string>
|
||||||
</resources>
|
</resources>
|
@@ -160,4 +160,6 @@
|
|||||||
<string name="stack_trace_share_system_build_id">System Build ID</string>
|
<string name="stack_trace_share_system_build_id">System Build ID</string>
|
||||||
<string name="stack_trace_share_package_name">App Package Name</string>
|
<string name="stack_trace_share_package_name">App Package Name</string>
|
||||||
<string name="stack_trace_share_other">Other Requirement</string>
|
<string name="stack_trace_share_other">Other Requirement</string>
|
||||||
|
<string name="share_with_file">Share errors stacktrace with file</string>
|
||||||
|
<string name="share_with_file_tip">Share errors stacktrace using files instead of text</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
5
module-app/src/main/res/xml/file_paths.xml
Normal file
5
module-app/src/main/res/xml/file_paths.xml
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<paths xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<cache-path name="cache" path="." />
|
||||||
|
<external-path name="external" path="." />
|
||||||
|
</paths>
|
Reference in New Issue
Block a user