issue#123 added an option to share crash report
This commit is contained in:
parent
ca19cb196c
commit
30b1f031ff
6 changed files with 155 additions and 2 deletions
|
@ -16,9 +16,11 @@ package code.name.monkey.retromusic
|
|||
|
||||
import android.app.Application
|
||||
import android.widget.Toast
|
||||
import cat.ereza.customactivityoncrash.config.CaocConfig
|
||||
import code.name.monkey.appthemehelper.ThemeStore
|
||||
import code.name.monkey.appthemehelper.util.VersionUtils
|
||||
import code.name.monkey.retromusic.Constants.PRO_VERSION_PRODUCT_ID
|
||||
import code.name.monkey.retromusic.activities.ErrorActivity
|
||||
import code.name.monkey.retromusic.appshortcuts.DynamicShortcutManager
|
||||
import code.name.monkey.retromusic.helper.WallpaperAccentManager
|
||||
import com.anjlab.android.iab.v3.BillingProcessor
|
||||
|
@ -69,6 +71,9 @@ class App : Application() {
|
|||
|
||||
override fun onBillingInitialized() {}
|
||||
})
|
||||
|
||||
// setting Error activity
|
||||
CaocConfig.Builder.create().errorActivity(ErrorActivity::class.java).apply()
|
||||
}
|
||||
|
||||
override fun onTerminate() {
|
||||
|
|
|
@ -0,0 +1,80 @@
|
|||
package code.name.monkey.retromusic.activities
|
||||
|
||||
import android.os.Bundle
|
||||
import android.widget.Button
|
||||
import android.widget.ImageView
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import cat.ereza.customactivityoncrash.CustomActivityOnCrash
|
||||
import code.name.monkey.retromusic.R
|
||||
import code.name.monkey.retromusic.util.FileUtils.createFile
|
||||
import code.name.monkey.retromusic.util.Share.shareFile
|
||||
import java.text.DateFormat
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.*
|
||||
|
||||
class ErrorActivity : AppCompatActivity() {
|
||||
private val dayFormat: DateFormat = SimpleDateFormat("yyyy-MM-dd", Locale.getDefault())
|
||||
private val ReportPrefix = "bug_report-"
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.customactivityoncrash_default_error_activity)
|
||||
|
||||
val restartButton =
|
||||
findViewById<Button>(R.id.customactivityoncrash_error_activity_restart_button)
|
||||
|
||||
val config = CustomActivityOnCrash.getConfigFromIntent(intent)
|
||||
if (config == null) {
|
||||
finish()
|
||||
return
|
||||
}
|
||||
restartButton.setText(R.string.customactivityoncrash_error_activity_restart_app)
|
||||
restartButton.setOnClickListener {
|
||||
CustomActivityOnCrash.restartApplication(
|
||||
this@ErrorActivity,
|
||||
config
|
||||
)
|
||||
}
|
||||
val moreInfoButton =
|
||||
findViewById<Button>(R.id.customactivityoncrash_error_activity_more_info_button)
|
||||
|
||||
moreInfoButton.setOnClickListener { //We retrieve all the error data and show it
|
||||
AlertDialog.Builder(this@ErrorActivity)
|
||||
.setTitle(R.string.customactivityoncrash_error_activity_error_details_title)
|
||||
.setMessage(
|
||||
CustomActivityOnCrash.getAllErrorDetailsFromIntent(
|
||||
this@ErrorActivity,
|
||||
intent
|
||||
)
|
||||
)
|
||||
.setPositiveButton(
|
||||
R.string.customactivityoncrash_error_activity_error_details_close,
|
||||
null
|
||||
)
|
||||
.setNeutralButton(
|
||||
R.string.customactivityoncrash_error_activity_error_details_share
|
||||
) { dialog, which ->
|
||||
|
||||
val bugReport = createFile(
|
||||
context = this,
|
||||
"Bug Report",
|
||||
"$ReportPrefix${dayFormat.format(Date())}",
|
||||
CustomActivityOnCrash.getAllErrorDetailsFromIntent(
|
||||
this@ErrorActivity,
|
||||
intent
|
||||
), ".txt"
|
||||
)
|
||||
shareFile(this, bugReport)
|
||||
}
|
||||
.show()
|
||||
}
|
||||
val errorActivityDrawableId = config.errorDrawable
|
||||
val errorImageView =
|
||||
findViewById<ImageView>(R.id.customactivityoncrash_error_activity_image)
|
||||
if (errorActivityDrawableId != null) {
|
||||
errorImageView.setImageResource(
|
||||
errorActivityDrawableId
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -2,7 +2,10 @@ package code.name.monkey.retromusic.util
|
|||
|
||||
import android.content.Context
|
||||
import android.net.Uri
|
||||
import android.util.Log
|
||||
import java.io.File
|
||||
import java.io.IOException
|
||||
|
||||
|
||||
object FileUtils {
|
||||
fun copyFileToUri(context: Context, fromFile: File, toUri: Uri) {
|
||||
|
@ -13,4 +16,45 @@ object FileUtils {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* creates a new file in storage in app specific directory.
|
||||
*
|
||||
* @return the file
|
||||
* @throws IOException
|
||||
*/
|
||||
fun createFile(context: Context, directoryName: String, fileName: String, body: String, fileType: String): File {
|
||||
val root = createDirectory(context, directoryName)
|
||||
val filePath = "$root/$fileName$fileType"
|
||||
val file = File(filePath)
|
||||
|
||||
// create file if not exist
|
||||
if (!file.exists()) {
|
||||
try {
|
||||
// create a new file and write text in it.
|
||||
file.createNewFile()
|
||||
file.writeText(body)
|
||||
Log.d(FileUtils::class.java.name, "File has been created and saved")
|
||||
} catch (e: IOException) {
|
||||
Log.d(FileUtils::class.java.name, e.message.toString())
|
||||
}
|
||||
}
|
||||
return file
|
||||
}
|
||||
|
||||
/**
|
||||
* creates a new directory in storage in app specific directory.
|
||||
*
|
||||
* @return the file
|
||||
*/
|
||||
private fun createDirectory(context: Context, directoryName: String): File {
|
||||
val file = File(
|
||||
context.getExternalFilesDir(directoryName)
|
||||
.toString()
|
||||
)
|
||||
if (!file.exists()) {
|
||||
file.mkdir()
|
||||
}
|
||||
return file
|
||||
}
|
||||
}
|
|
@ -18,6 +18,8 @@ import android.content.Context
|
|||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import androidx.core.app.ActivityCompat
|
||||
import androidx.core.content.FileProvider
|
||||
import java.io.File
|
||||
|
||||
/**
|
||||
* Created by hemanths on 2020-02-02.
|
||||
|
@ -30,4 +32,16 @@ object Share {
|
|||
feedIntent.putExtra(Intent.EXTRA_STREAM, uri)
|
||||
ActivityCompat.startActivity(context, feedIntent, null)
|
||||
}
|
||||
|
||||
fun shareFile(context: Context, file: File) {
|
||||
val attachmentUri = FileProvider.getUriForFile(
|
||||
context,
|
||||
context.applicationContext.packageName,
|
||||
file
|
||||
)
|
||||
val sharingIntent = Intent(Intent.ACTION_SEND)
|
||||
sharingIntent.type = "text/*"
|
||||
sharingIntent.putExtra(Intent.EXTRA_STREAM, attachmentUri)
|
||||
context.startActivity(Intent.createChooser(sharingIntent, "send bug report"))
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue