b8ne / react-native-pusher-push-notifications

Manage pusher interest subscriptions and notification events in Javascript.
MIT License
97 stars 85 forks source link

Android push notifications #32

Closed kulkarniankita closed 5 years ago

kulkarniankita commented 5 years ago

Following are the steps I took to get push notifications to register but this module is not working at all for android. I know that this is still under development but any help will be appreciated in order to figure this out for android.

dependencies {
    compile project(':react-native-pusher-push-notifications')

    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation "com.android.support:appcompat-v7:27.1.1"
    implementation "com.android.support:support-media-compat:27.1.1"
    implementation "com.android.support:recyclerview-v7:27.1.1"

    implementation "com.facebook.react:react-native:0.55.4"  // From node_modules

    implementation 'com.google.firebase:firebase-core:16.0.1'

// push notifications via beams start
    implementation 'com.google.firebase:firebase-messaging:17.1.0'
    implementation 'com.pusher:push-notifications-android:1.0.1'
// push notifications via beams end
 }
// push notifications via beam
apply plugin: 'com.google.gms.google-services'

MainApplication.java:

import android.app.Application;

import com.facebook.react.ReactApplication;
import com.b8ne.RNPusherPushNotifications.RNPusherPushNotificationsPackage;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
import com.facebook.soloader.SoLoader;

import java.util.Arrays;
import java.util.List;

public class MainApplication extends Application implements ReactApplication {

  private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
    @Override
    public boolean getUseDeveloperSupport() {
      return BuildConfig.DEBUG;
    }

    @Override
    protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
          new MainReactPackage(),
            new RNPusherPushNotificationsPackage(),
      );
    }
}

settings.gradle:

include ':react-native-pusher-push-notifications'
project(':react-native-pusher-push-notifications').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-pusher-push-notifications/android')

The above did not register the device and did not subscribe to any interests either. Any suggestions?

hyunjin-oh commented 5 years ago

Trying to get it work on Android too, any suggestions would be appreciated.

kulkarniankita commented 5 years ago

@hyunjin-oh, unfortunately, it did not work on android for me through react native but I manually added the following line in my MainApplication class to get a notification and subscribe to an interest.

PushNotifications.start(getApplicationContext(), "<id>");
PushNotifications.subscribe("<interest-name>");
hyunjin-oh commented 5 years ago

@kulkarniankita, I think I should do that too. Thanks a lot for sharing your solution!

mikebridge commented 5 years ago

When we're calling subscribe in android, it looks like the callbacks don't get executed:


import RNPusherPushNotifications from "react-native-pusher-push-notifications";

// ...
console.log(`Subscribing to "${interest}"`);
RNPusherPushNotifications.subscribe(
    interest,
    (statusCode, response) => {
        console.error(statusCode, response);
    },
    () => {
        console.log(`Subscribed to ${interest}`);
    }
);

I don't see either callback's console messages RN debugger, but I do see the "Subscribing to..." message.

massivebrains commented 5 years ago

+1

massivebrains commented 5 years ago

Please help...

Anyone got this working on android yet????

massivebrains commented 5 years ago

@mikebridge Please.. Have you being able to get this working??

hpaul commented 5 years ago

Hello,

The android implementation of this modules it's out-of-date, it uses the old Pusher API, checkout this link for further details. So it doesn't work anyway, I used Android Studio logging to see what happens.

I/System.out: Creating Pusher with App Key: cfe9cfc6-f219-49cd-88c8-9f4b0d3ef810(HTTPLog)-Static: isSBSettingEnabled false
    (HTTPLog)-Static: isSBSettingEnabled false
W/FlurryAgent: Analytics report sent.
V/AsyncHttpRH: Progress 189 from 189 (100%)
E/PUploadSuccess: [token upload] Received status 404 with: {"error":"Wrong app key provided","desc":"This app key looks like a Beams Instance Id. If you'd like to use Beams, you can find the SDKs here: https:\/\/docs.pusher.com\/push-notifications."}
D/PUSHER_WRAPPER: FCM Registration failed with code 404 {"error":"Wrong app key provided","desc":"This app key looks like a Beams Instance Id. If you'd like to use Beams, you can find the SDKs here: https:\/\/docs.pusher.com\/push-notifications."}

Now, what should be done, is it to rewrite the android part using this new package, which is a way lot easier to use, from what I saw. https://docs.pusher.com/beams/reference/server-sdk-java-kotlin.

UPDATE: Didn't saw the Pull Request from @mikebridge, he did implemented the Beams SDK Checkout this #33