【问题标题】:Can't create a PushNotification instance无法创建 PushNotification 实例
【发布时间】:2018-06-12 08:24:20
【问题描述】:

我为我的 Android 应用注册了 Pusher/Beams 帐户。我能够设置它没有问题。但是当我去简单地创建一个新的 pushnotification 实例时,我遇到了一个错误。 Pusher 的文档使用以下代码:

String instanceId = "YOUR_INSTANCE_ID_HERE";
String secretKey = "YOUR_SECRET_KEY_HERE";

PushNotifications pushNotifications = new PushNotifications(instanceId,secretKey);

但是,当我将其复制并粘贴到 Android Studios 中时,我收到一条错误消息,提示 PushNotifications 不接受字符串。我很困惑为什么会这样。 这是我的代码:

import android.content.SharedPreferences;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import com.pusher.pushnotifications.PushNotifications;

public class MainActivity extends AppCompatActivity {
    String instanceId = "YOUR_INSTANCE_ID_HERE";
    String secretKey = "YOUR_SECRET_KEY_HERE";

    PushNotifications pushNotifications = new PushNotifications(instanceId, secretKey);

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        PushNotifications.start(getApplicationContext(), "my_instance_id");
        PushNotifications.subscribe("hello");
}

这是错误的屏幕截图。

【问题讨论】:

    标签: android push-notification pusher android-push-notification


    【解决方案1】:

    您不能将字符串作为第一个参数传递给PushNotification 构造函数。您传递的参数不正确。

    当前是:

    PushNotifications pushNotifications = new PushNotifications(instanceId, secretKey);
    

    改为:

    PushNotificationsInstance pushNotifications =
        new PushNotificationsInstance(getApplicationContext(), instanceId);
    

    它会起作用的。

    点击这里了解更多信息:https://docs.pusher.com/beams/reference/android#quickstart

    【讨论】:

      【解决方案2】:

      试试这个:PushNotificationsInstance pushNotifications = new PushNotificationsInstance (instanceId, secretKey);

      【讨论】:

        猜你喜欢
        • 2020-01-16
        • 2019-05-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-01-11
        相关资源
        最近更新 更多