From 905214b49e095eddc3a746e4f1f4f20a5339067a Mon Sep 17 00:00:00 2001 From: ua1zbe Date: Mon, 28 Sep 2026 12:19:40 +0000 Subject: [PATCH] =?UTF-8?q?=D0=9F=D1=83=D1=88-=D1=83=D0=B2=D0=B5=D0=B4?= =?UTF-8?q?=D0=BE=D0=BC=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F=20RuStore=20=D0=B2?= =?UTF-8?q?=20apk-webview:=20SDK,=20=D1=81=D0=B5=D1=80=D0=B2=D0=B8=D1=81?= =?UTF-8?q?=20=D0=BF=D1=80=D0=B8=D1=91=D0=BC=D0=B0,=20=D0=BA=D0=B0=D0=BD?= =?UTF-8?q?=D0=B0=D0=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ua1zbe/bus127/PushMessagingService.java | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 apk-webview/app/src/main/java/ru/ua1zbe/bus127/PushMessagingService.java diff --git a/apk-webview/app/src/main/java/ru/ua1zbe/bus127/PushMessagingService.java b/apk-webview/app/src/main/java/ru/ua1zbe/bus127/PushMessagingService.java new file mode 100644 index 0000000..7fdab79 --- /dev/null +++ b/apk-webview/app/src/main/java/ru/ua1zbe/bus127/PushMessagingService.java @@ -0,0 +1,75 @@ +package ru.ua1zbe.bus127; + +import android.app.Notification; +import android.app.NotificationManager; +import android.util.Log; + +import java.util.List; +import java.util.Map; + +import ru.rustore.sdk.pushclient.messaging.exception.RuStorePushClientException; +import ru.rustore.sdk.pushclient.messaging.model.RemoteMessage; +import ru.rustore.sdk.pushclient.messaging.service.RuStoreMessagingService; +import ru.ua1zbe.bus127.push.PushStore; + +/** + * Приём пуш-уведомлений RuStore. + * + * Если сервер прислал секцию notification — SDK показывает уведомление сам. + * Если пришли только data (title/body) — показываем уведомление сами. + */ +public class PushMessagingService extends RuStoreMessagingService { + + @Override + public void onNewToken(String token) { + Log.i(TAG, "onNewToken: " + token); + PushStore.setToken(this, token); + } + + @Override + public void onMessageReceived(RemoteMessage message) { + if (message.getNotification() != null) { + Log.i(TAG, "push displayed by SDK: " + message.getData()); + return; + } + Map data = message.getData(); + String title = data.get("title"); + if (title == null || title.isEmpty()) { + title = getString(R.string.app_name); + } + String body = data.get("body"); + if (body == null) { + body = ""; + } + if (!title.isEmpty() || !body.isEmpty()) { + showPush(title, body, data.get("url")); + } + } + + @Override + public void onDeletedMessages() { + Log.i(TAG, "onDeletedMessages"); + } + + @Override + public void onError(List errors) { + for (RuStorePushClientException e : errors) { + Log.w(TAG, "error", e); + } + } + + private void showPush(String title, String body, String url) { + Notification.Builder b = new Notification.Builder(this, Bus127App.CHANNEL_ID) + .setContentTitle(title) + .setContentText(body) + .setSmallIcon(R.mipmap.ic_launcher) + .setAutoCancel(true); + if (url != null && !url.isEmpty()) { + b.setContentIntent(PushIntents.web(this, url)); + } + getSystemService(NotificationManager.class).notify(NOTIFICATION_ID, b.build()); + } + + private static final String TAG = "RuStorePush"; + private static final int NOTIFICATION_ID = 127; +}