🔥 🔥 🔥App
错误日志、请求数据、Log
信息抓取,同时每次触发错误,通过手机消息列表弹出,增加浮动按钮入口,作为Tool
工具总入口。
dependencies {
implementation 'io.github.weishuaidev:xtool:1.4.0'
}
默认工具库已经默认成功初始化,同时设置关闭消息通知栏,如果需要开启通知栏,可以在Application#onCreate()
方法调用XToolReporter.enableNotification()
-
加载资源库
XToolReporter.init(getApplication());
-
设置消息通知栏
XToolReporter.disableNotification(); 关闭 XToolReporter.enableNotification(); 开启
抓取总共4种数据,分别:Crashes、Exceptions、Http、Log
-
try{ } catch (e: Exception) { //log caught Exception XToolReporter.logException(e) }
-
val client: OkHttpClient = OkHttpClient.Builder() .addInterceptor(LoggingInterceptor()) .build()
-
LoggerUtils.i("info") LoggerUtils.e("error") LoggerUtils.d("debug") LoggerUtils.v("verbose") LoggerUtils.w("warn")
-
获取悬浮按钮权限,并启动悬浮按钮,通过点击悬浮按钮跳转到
ChooseModuleActivity
界面。如果不需要悬浮按钮入口,可以直接跳转到ChooseModuleActivity
,也不需要申请权限。override fun onCreate(savedInstanceState: Bundle?) { View.setOnClickListener { //关闭悬浮按钮 XToolReporter.disableAndzu() //申请悬浮按钮权限 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !Settings.canDrawOverlays(this)) { val intent = Intent( Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:$packageName") ) startActivityForResult(intent, 1) } else { //初始化悬浮按钮 XToolReporter.initBubbles(SampleApplication.appContext) } } } override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { if (requestCode == 1) { if (resultCode == RESULT_OK) { //初始化悬浮按钮 XToolReporter.initBubbles(SampleApplication.appContext) } } else { super.onActivityResult(requestCode, resultCode, data) } }
-
资源回收
override fun onDestroy() { super.onDestroy() try { XToolReporter.recycle() } catch (e: Exception) { e.printStackTrace() } }
In-App Android Debugging Tool With Enhanced Logging, Networking Info, Crash reporting And More.
CrashReporter is a handy tool to capture app crashes and save them in a file
在开源的同时,解决别人需求,是一件很高兴的事。
赠人玫瑰,手留余香
-
Email:linwei9605@gmail.com
-
Blog: https://offer.github.io/
Copyright 2022 offer
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.```