Не удается создать экземпляр PushNotification - PullRequest
0 голосов
/ 12 июня 2018

Я зарегистрировал учетную запись Pusher / Beams для своего приложения для Android.Я был в состоянии установить это без проблем.Но когда я просто создал новый экземпляр 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");
}

Вот скриншот ошибки.

enter image description here

Ответы [ 2 ]

0 голосов
/ 12 июня 2018

Нельзя передать строку в качестве первого аргумента конструктору PushNotification .Вы передаете неверные параметры.

Текущий:

PushNotifications pushNotifications = new PushNotifications(instanceId, secretKey);

Изменить на:

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

Это будет работать.

Проверьте здесь для получения дополнительной информации: https://docs.pusher.com/beams/reference/android#quickstart

0 голосов
/ 12 июня 2018

Попробуйте это: PushNotificationsInstance pushNotifications = new PushNotificationsInstance (instanceId, secretKey);

...