From 74d3f395cef704db60496a60064f8748fc0f6061 Mon Sep 17 00:00:00 2001 From: ua1zbe Date: Mon, 28 Sep 2026 12:19:39 +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 --- .../main/java/ru/ua1zbe/bus127/Bus127App.java | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 apk-webview/app/src/main/java/ru/ua1zbe/bus127/Bus127App.java diff --git a/apk-webview/app/src/main/java/ru/ua1zbe/bus127/Bus127App.java b/apk-webview/app/src/main/java/ru/ua1zbe/bus127/Bus127App.java new file mode 100644 index 0000000..9cf740b --- /dev/null +++ b/apk-webview/app/src/main/java/ru/ua1zbe/bus127/Bus127App.java @@ -0,0 +1,60 @@ +package ru.ua1zbe.bus127; + +import android.app.Application; +import android.app.NotificationChannel; +import android.app.NotificationManager; +import android.util.Log; + +import ru.rustore.sdk.pushclient.RuStorePushClient; +import ru.ua1zbe.bus127.push.PushStore; + +/** + * Инициализация RuStore Push SDK. + * + * project_id и topic берутся из консоли RuStore (Push-уведомления > Проекты). + * Сервисный токен в приложении не хранится — он нужен только серверу + * для вызова https://vkpns.rustore.ru/v1/projects/{project_id}/messages:send + */ +public class Bus127App extends Application { + + public static final String CHANNEL_ID = "bus127_push"; + + @Override + public void onCreate() { + super.onCreate(); + createPushChannel(); + initRuStorePush(); + } + + private void createPushChannel() { + NotificationManager nm = getSystemService(NotificationManager.class); + nm.createNotificationChannel(new NotificationChannel( + CHANNEL_ID, + getString(R.string.push_channel_name), + NotificationManager.IMPORTANCE_HIGH)); + } + + private void initRuStorePush() { + try { + RuStorePushClient.INSTANCE.init(this, RUSTORE_PROJECT_ID); + RuStorePushClient.INSTANCE.getToken() + .addOnSuccessListener(token -> { + Log.i(TAG, "push token: " + token); + PushStore.setToken(this, token); + RuStorePushClient.INSTANCE.subscribeToTopic(PUSH_TOPIC) + .addOnSuccessListener(v -> + Log.i(TAG, "subscribed to " + PUSH_TOPIC)) + .addOnFailureListener(e -> + Log.w(TAG, "subscribe to " + PUSH_TOPIC + " failed", e)); + }) + .addOnFailureListener(e -> + Log.w(TAG, "getToken failed", e)); + } catch (Exception e) { + Log.w(TAG, "init failed", e); + } + } + + private static final String TAG = "RuStorePush"; + private static final String RUSTORE_PROJECT_ID = "upSEOtZyXP96tskl4hf-442AqciCUTxs"; + private static final String PUSH_TOPIC = "bus127"; +}