From 8eb15ab9a4a39852fd156993c8ea16123dfb08c1 Mon Sep 17 00:00:00 2001 From: Yegor Vialov Date: Mon, 25 May 2020 11:05:16 +0000 Subject: [PATCH] Notification channel description --- .../hassclient/MessagingService.java | 14 +++++--------- .../hassclient/NotificationActionReceiver.java | 7 ++----- .../com/keyboardcrumbs/hassclient/SendTask.java | 2 -- 3 files changed, 7 insertions(+), 16 deletions(-) diff --git a/android/app/src/main/java/com/keyboardcrumbs/hassclient/MessagingService.java b/android/app/src/main/java/com/keyboardcrumbs/hassclient/MessagingService.java index f1efd52..bcb5a83 100644 --- a/android/app/src/main/java/com/keyboardcrumbs/hassclient/MessagingService.java +++ b/android/app/src/main/java/com/keyboardcrumbs/hassclient/MessagingService.java @@ -15,7 +15,6 @@ import android.media.RingtoneManager; import android.net.Uri; import android.os.Build; import androidx.core.app.NotificationCompat; -import android.util.Log; import com.google.firebase.messaging.FirebaseMessagingService; import com.google.firebase.messaging.RemoteMessage; @@ -31,10 +30,8 @@ public class MessagingService extends FirebaseMessagingService { @Override public void onMessageReceived(RemoteMessage remoteMessage) { - Log.d(TAG, "From: " + remoteMessage.getFrom()); Map data = remoteMessage.getData(); if (data.size() > 0) { - Log.d(TAG, "Message data payload: " + data); if (data.containsKey("body") || data.containsKey("title")) { sendNotification(data); } @@ -43,18 +40,18 @@ public class MessagingService extends FirebaseMessagingService { @Override public void onNewToken(String token) { - Log.d(TAG, "Refreshed token: " + token); //TODO update token } private void sendNotification(Map data) { - String channelId, messageBody, messageTitle, imageUrl; - String nTag; + String channelId, messageBody, messageTitle, imageUrl, nTag, channelDescription; boolean autoCancel; if (!data.containsKey("channelId")) { channelId = "ha_notify"; + channelDescription = "Default notification channel"; } else { channelId = data.get("channelId"); + channelDescription = channelId; } if (!data.containsKey("body")) { messageBody = ""; @@ -71,7 +68,6 @@ public class MessagingService extends FirebaseMessagingService { } else { nTag = data.get("tag"); } - Log.d(TAG, "Notification tag: " + nTag); if (data.containsKey("dismiss")) { try { boolean dismiss = Boolean.parseBoolean(data.get("dismiss")); @@ -132,8 +128,8 @@ public class MessagingService extends FirebaseMessagingService { // Since android Oreo notification channel is needed. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { NotificationChannel channel = new NotificationChannel(channelId, - "Home Assistant notifications", - NotificationManager.IMPORTANCE_DEFAULT); + channelDescription, + NotificationManager.IMPORTANCE_HIGH); notificationManager.createNotificationChannel(channel); } diff --git a/android/app/src/main/java/com/keyboardcrumbs/hassclient/NotificationActionReceiver.java b/android/app/src/main/java/com/keyboardcrumbs/hassclient/NotificationActionReceiver.java index 7030a83..949f37f 100644 --- a/android/app/src/main/java/com/keyboardcrumbs/hassclient/NotificationActionReceiver.java +++ b/android/app/src/main/java/com/keyboardcrumbs/hassclient/NotificationActionReceiver.java @@ -22,7 +22,6 @@ public class NotificationActionReceiver extends BroadcastReceiver { String rawActionData = intent.getStringExtra("actionData"); if (intent.hasExtra("tag")) { String notificationTag = intent.getStringExtra("tag"); - Log.d(TAG, "Canceling notification by tag: " + notificationTag); NotificationManager notificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.cancel(notificationTag, 0); } @@ -36,7 +35,6 @@ public class NotificationActionReceiver extends BroadcastReceiver { ":" + prefs.getString("flutter.hassio-port", "") + "/api/webhook/" + webhookId; JSONObject actionData = new JSONObject(rawActionData); - Log.d(TAG, "request url: " + requestUrl); if (URLUtil.isValidUrl(requestUrl)) { JSONObject dataToSend = new JSONObject(); JSONObject requestData = new JSONObject(); @@ -53,17 +51,16 @@ public class NotificationActionReceiver extends BroadcastReceiver { } dataToSend.put("data", requestData); String stringRequest = dataToSend.toString(); - Log.d(TAG, "Data to send home: " + stringRequest); SendTask sendTask = new SendTask(); sendTask.execute(requestUrl, stringRequest); } else { - Log.w(TAG, "Invalid url"); + Log.w(TAG, "Invalid HA url"); } } catch (Exception e) { Log.e(TAG, "Error handling notification action", e); } } else { - Log.d(TAG, "Webhook id not found"); + Log.w(TAG, "Webhook id not found"); } } } \ No newline at end of file diff --git a/android/app/src/main/java/com/keyboardcrumbs/hassclient/SendTask.java b/android/app/src/main/java/com/keyboardcrumbs/hassclient/SendTask.java index c04192a..76571cd 100644 --- a/android/app/src/main/java/com/keyboardcrumbs/hassclient/SendTask.java +++ b/android/app/src/main/java/com/keyboardcrumbs/hassclient/SendTask.java @@ -26,7 +26,6 @@ public class SendTask extends AsyncTask { String data = params[1]; try { - Log.d(TAG, "Connecting and sending..."); URL url = new URL(urlString); HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection(); urlConnection.setRequestMethod("POST"); @@ -38,7 +37,6 @@ public class SendTask extends AsyncTask { int responseCode = urlConnection.getResponseCode(); - Log.d(TAG, "responseCode: " + responseCode); urlConnection.disconnect(); } catch (Exception e) { Log.e(TAG, "Error sending data", e);