Android独立应用程序中未创建Expo推送令牌。
创始人
2024-10-07 15:01:55
0次

在Expo中,推送令牌是用于向设备发送推送通知的重要标识符。在Android独立应用程序中,Expo推送令牌可能没有被正确创建,导致推送通知无法正常工作。

以下是在Android独立应用程序中创建Expo推送令牌的示例代码:

  1. 在app/build.gradle文件中添加以下依赖项:
implementation 'com.google.android.gms:play-services-gcm:12.0.1'
implementation 'com.google.firebase:firebase-messaging:12.0.1'
  1. 创建PushNotification.java类,并添加以下代码:
import android.content.Context;

import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GoogleApiAvailability;
import com.google.android.gms.common.GooglePlayServicesUtil;

import io.expo.client.BuildConfig;
import io.expo.client.ExpoAndroidNotificationsDelegate;
import io.expo.client.ExponentManifest;
import io.expo.client.kernel.KernelConstants;
import versioned.host.exp.exponent.Constants;
import versioned.host.exp.exponent.ExponentApplication;

public class PushNotification {
  public static void register(Context context) {
    if (!ExpoAndroidNotificationsDelegate.isInitialized()) {
      ExponentApplication application = (ExponentApplication) context.getApplicationContext();
      ExponentManifest manifest = application.getManifest();
      String experienceId = manifest.optString(ExponentManifest.MANIFEST_ID_KEY);

      if (experienceId != null && experienceId.length() > 0) {
        if (GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(context) == ConnectionResult.SUCCESS) {
          ExpoAndroidNotificationsDelegate.init(application, experienceId, manifest);
        } else {
          // Handle error
        }
      } else {
        // Handle error
      }
    }
  }

  public static void unregister(Context context) {
    if (ExpoAndroidNotificationsDelegate.isInitialized()) {
      ExpoAndroidNotificationsDelegate delegate = ExpoAndroidNotificationsDelegate.getInstance();

      if (delegate != null) {
        delegate.stop();

        ExpoAndroidNotificationsDelegate.unpinDeviceToken(context);
        ExpoAndroidNotificationsDelegate.release();

相关内容

热门资讯

2026教程!wpk私人局有透... 很多人使用云端 AI 时,都担心wpk私人局有透视吗、内部资料上传带来隐私风险。这款本地运行的 AI...
可靠教程!德扑之星透视辅助软件... 可靠教程!德扑之星透视辅助软件激活码,wepoker是不是有挂插件(本来存在有开挂)AI 是一款可以...
我来教教大家!微扑克透视脚本,... 我来教教大家!微扑克透视脚本,WPK到底有挂吗助手(原生真的是有辅助挂)主打本地运行的 AI 黑科技...
大家学习交流!wepokerp... 您好,大家学习交流!wepokerplus辅助,微扑克怎么开挂教程(最初真的是有开挂)这款游戏可以开...
新手必备!wepoker手机版... 很多人使用云端 AI 时,都担心wepoker手机版辅助、内部资料上传带来隐私风险。这款本地运行的 ...
技巧教程!wepoker透视脚... 一款 AI 游戏攻略黑科技工具上线,查攻略效率直接开挂。它整合版本更新、装备搭配、BOSS 打法、牌...
必赢方法!wepoker数据分... 您好:wepoker数据分析工具这款游戏可以开挂的,确实是有挂的,很多玩家在这款游戏中打牌都会发现很...
必知教程!!智星德州辅助译码插... 必知教程!!智星德州辅助译码插件靠谱吗,微扑克有挂么助手(切实是真的有辅助器)主打本地运行的 AI ...
一起来讨论!wepoker祈福... 很多人使用云端 AI 时,都担心wepoker祈福有用吗、内部资料上传带来隐私风险。这款本地运行的 ...
专业讨论!!wpk俱乐部有没有... 很多人使用云端 AI 时,都担心wpk俱乐部有没有辅助、内部资料上传带来隐私风险。这款本地运行的 A...