-
-
Save romansl/5c5c8e756ad20001ba8f to your computer and use it in GitHub Desktop.
Service-based HockeyApp sender.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<service | |
android:name=".app.services.ReportSenderService" | |
android:exported="false" | |
android:process=":report"/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.anytalkapp.app.utils | |
import android.content.Context | |
import android.content.Intent | |
import com.anytalkapp.app.services.ReportSenderService | |
import org.acra.ReportField | |
import org.acra.collector.CrashReportData | |
import org.acra.sender.ReportSender | |
import java.util.* | |
public class HockeySender : ReportSender { | |
override fun send(context: Context, report: CrashReportData) { | |
val log = "Package: " + report.get(ReportField.PACKAGE_NAME) + "\n" + | |
"Version: " + report.get(ReportField.APP_VERSION_CODE) + "\n" + | |
"Android: " + report.get(ReportField.ANDROID_VERSION) + "\n" + | |
"Manufacturer: " + android.os.Build.MANUFACTURER + "\n" + | |
"Model: " + report.get(ReportField.PHONE_MODEL) + "\n" + | |
"Date: " + Date() + "\n\n" + | |
report.get(ReportField.STACK_TRACE) + "\n" + | |
report.get(ReportField.LOGCAT) | |
val intent = Intent(context, ReportSenderService::class.java).apply { | |
putExtra(ReportSenderService.EXTRA_RAW, log) | |
putExtra(ReportSenderService.EXTRA_USER_ID, report.get(ReportField.INSTALLATION_ID) ?: "") | |
putExtra(ReportSenderService.EXTRA_CONTACT, report.get(ReportField.USER_EMAIL) ?: "") | |
putExtra(ReportSenderService.EXTRA_DESCRIPTION, report.get(ReportField.USER_COMMENT) ?: "") | |
} | |
context.startService(intent) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.anytalkapp.app.services | |
import android.app.IntentService | |
import android.content.Intent | |
import android.util.Log | |
import com.anytalkapp.BuildConfig | |
import com.anytalkapp.app.network.http.OkHTTP | |
import com.anytalkapp.common.HttpResponseException | |
import com.squareup.okhttp.FormEncodingBuilder | |
import com.squareup.okhttp.Request | |
class ReportSenderService : IntentService("ReportSender") { | |
override fun onHandleIntent(intent: Intent) { | |
Log.i(TAG, "Sending report...") | |
try { | |
val body = FormEncodingBuilder() | |
.add(EXTRA_RAW, intent.getStringExtra(EXTRA_RAW)) | |
.add(EXTRA_USER_ID, intent.getStringExtra(EXTRA_USER_ID)) | |
.add(EXTRA_CONTACT, intent.getStringExtra(EXTRA_CONTACT)) | |
.add(EXTRA_DESCRIPTION, intent.getStringExtra(EXTRA_DESCRIPTION)) | |
.build() | |
val request = Request.Builder() | |
.url("https://rink.hockeyapp.net/api/2/apps/${BuildConfig.HOCKEY_APP_ID}/crashes") | |
.post(body) | |
.build() | |
val response = OkHTTP.Instance.execute(request) | |
val responseCode = response.code() | |
if (responseCode < 200 || responseCode >= 300) { | |
throw HttpResponseException(responseCode, response.message()) | |
} | |
Log.i(TAG, "Done.") | |
} catch (e: Exception) { | |
Log.e(TAG, "", e) | |
} | |
} | |
companion object { | |
private const val TAG = "ReportSender" | |
const val EXTRA_RAW = "raw" | |
const val EXTRA_USER_ID = "userID" | |
const val EXTRA_CONTACT = "contact" | |
const val EXTRA_DESCRIPTION = "description" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment