1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-12-28 03:25:49 +01:00

added exception notifications

This commit is contained in:
Daniel Dakhno 2019-10-31 01:58:06 +01:00
parent 00b66d45e7
commit e955330268

View File

@ -1,5 +1,8 @@
package nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCharacteristic;
import android.content.BroadcastReceiver;
@ -7,6 +10,8 @@ import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.media.AudioManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;
@ -16,6 +21,8 @@ import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.FileOutputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.HashMap;
import java.util.UUID;
@ -416,6 +423,42 @@ public class QHybridSupport extends QHybridBaseSupport {
super.handleGBDeviceEvent(deviceEvent);
}
public void notifiyException(Exception e){
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
String sStackTrace = sw.toString();
Notification.Builder notificationBuilder = null;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
notificationBuilder = new Notification.Builder(getContext(), GB.NOTIFICATION_CHANNEL_ID);
} else {
notificationBuilder = new Notification.Builder(getContext());
}
notificationBuilder
.setContentTitle("Q Error")
.setSmallIcon(R.drawable.ic_notification_qhybrid)
.setContentText(sStackTrace)
.setStyle(new Notification.BigTextStyle())
.build();
Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts(
"mailto","dakhnod@gmail.com", null));
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Exception Report");
emailIntent.putExtra(Intent.EXTRA_TEXT, "Here's a crash from your stupid app: \n\n" + sStackTrace);
PendingIntent intent = PendingIntent.getActivity(getContext(), 0, emailIntent, 0);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
notificationBuilder.addAction(new Notification.Action(0, "report", intent));
}else{
notificationBuilder.addAction(0, "report", intent);
}
((NotificationManager) getContext().getSystemService(Context.NOTIFICATION_SERVICE)).notify((int) System.currentTimeMillis(), notificationBuilder.build());
}
@Override
public boolean onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {
switch (characteristic.getUuid().toString()) {