-1

I signed up for a Pusher/Beams account for my Android app. I was able to set it up no problem. But when I went to simply create a new pushnotification instance I ran into an error. The documentation from Pusher uses this code:

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

PushNotifications pushNotifications = new PushNotifications(instanceId,secretKey);

However when I literally copy and paste that into Android Studios I get an error saying PushNotifications does not accept Strings. I am baffled as to why this is happening. Here is my code:

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");
}

Here is a screenshot of the error.

enter image description here

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Grant Walton
  • 51
  • 2
  • 7

2 Answers2

0

Try this : PushNotificationsInstance pushNotifications = new PushNotificationsInstance (instanceId, secretKey);

clst
  • 111
  • 1
  • 11
0

You can not pass string as first argument to PushNotification constructor. You are passing incorrect parameters.

Current is:

PushNotifications pushNotifications = new PushNotifications(instanceId, secretKey);

Change to:

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

It will work.

Check here for more information : https://docs.pusher.com/beams/reference/android#quickstart

Vikasdeep Singh
  • 20,983
  • 15
  • 78
  • 104