Skip to content

Commit

Permalink
add CrashActivity
Browse files Browse the repository at this point in the history
  • Loading branch information
fengzhizi715 committed Oct 14, 2021
1 parent 1a50ab6 commit a091b60
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 14 deletions.
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
android:screenOrientation="portrait"/>

<activity
android:name="cn.salesuite.saf.kotlin.activity.JNIActivity"
android:name="cn.salesuite.saf.kotlin.activity.CrashActivity"
android:configChanges="orientation|keyboardHidden"
android:screenOrientation="portrait"/>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package cn.salesuite.saf.kotlin.activity

import android.Manifest
import android.app.Activity
import android.content.pm.PackageManager
import android.os.Bundle
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat

/**
*
* @FileName:
* cn.salesuite.saf.kotlin.activity.CrashActivity
* @author: Tony Shen
* @date: 2021-10-14 21:08
* @version: V1.0 <描述当前版本功能>
*/
class CrashActivity: Activity() {

public override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

val permissionCheck = ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)
if (permissionCheck != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), 0)
}

throw NullPointerException()
}

override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {

if (requestCode==0) {

}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ class MainActivity : BaseActivity() {
startActivity(intent)
}

// text8.setOnClickListener {
//
// val intent = Intent(this@MainActivity, JNIActivity::class.java)
// startActivity(intent)
// }
text8.setOnClickListener {

val intent = Intent(this@MainActivity, CrashActivity::class.java)
startActivity(intent)
}
}
}
15 changes: 15 additions & 0 deletions app/src/main/java/cn/salesuite/saf/kotlin/app/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import com.safframework.log.configL
import com.safframework.log.converter.gson.GsonConverter
import com.safframework.log.debugview.DebugViewWrapper
import com.safframework.log.debugview.modules.TimerModule
import com.safframework.log.printer.FilePrinter
import com.safframework.log.printer.file.FileBuilder
import com.safframework.log.utils.CrashUtils

/**
*
Expand All @@ -22,6 +25,12 @@ var application: Application? = null

class App : Application() {

private var crashPrinter: FilePrinter

init{
crashPrinter = FileBuilder().folderPath("/storage/emulated/0/crash_logs").build()
}

override fun attachBaseContext(base: Context?) {
super.attachBaseContext(base)
application = this
Expand All @@ -36,6 +45,12 @@ class App : Application() {
converter = GsonConverter()
}

CrashUtils.init(tag = "crashTag",printer = crashPrinter, onCrashListener = object : CrashUtils.OnCrashListener {
override fun onCrash(crashInfo: String, e: Throwable) {

}
})

initDebugView()
}

Expand Down
16 changes: 8 additions & 8 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@
android:gravity="center"
android:text="在 Java 中使用 L"/>

<!-- <TextView-->
<!-- android:id="@+id/text8"-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="50dp"-->
<!-- android:layout_margin="10dp"-->
<!-- android:background="@drawable/textview_border"-->
<!-- android:gravity="center"-->
<!-- android:text="在 JNI 中使用 L"/>-->
<TextView
android:id="@+id/text8"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_margin="10dp"
android:background="@drawable/textview_border"
android:gravity="center"
android:text="收集奔溃日志"/>

</LinearLayout>

0 comments on commit a091b60

Please sign in to comment.