tinycreative / react-native-intercom

React Native wrapper for Intercom.io
MIT License
405 stars 279 forks source link

Android: Can't get push notification when app is off #151

Closed tobob closed 5 years ago

tobob commented 6 years ago

Im able to get push notification when app is on or in background, but then app is off with task manager I didn't get nothing

When I try to use only FCM dashboard Im getting it even if app is off

android/app/build.grandle

    compile(project(':react-native-fcm')) {
      exclude group: "com.google.firebase"
    }
    compile ('com.google.firebase:firebase-core:11.+') {
        force = true;
    }
    compile ('com.google.firebase:firebase-messaging:11.+') {
        force = true;
    }
    compile('io.intercom.android:intercom-sdk-base:4.+') {
        force = true;
    }
    compile('io.intercom.android:intercom-sdk-fcm:4.+') {
        force = true;
    }

AndroidManifest.xml

    <application
      android:name="io.bla.bla.MainApplication"
      android:allowBackup="true"
      android:label="@string/app_name"
      android:icon="@mipmap/ic_launcher"
      android:theme="@style/AppTheme"
      xmlns:tools="http://schemas.android.com/tools">
.....
      <service
        android:name="com.robinpowered.react.Intercom.IntercomIntentService"
        android:exported="false">
        <intent-filter
            android:priority="999">
            <action android:name="com.google.android.c2dm.intent.RECEIVE"/>
        </intent-filter>
    </service>

    <receiver
     android:name="io.intercom.android.sdk.push.IntercomPushBroadcastReceiver"
     tools:replace="android:exported"
     android:exported="true" />
    </application>

permisions from AndroidManifest.xml

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
    <uses-permission android:name="android.permission.VIBRATE"/>
    <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
    <uses-permission android:name="android.permission.ACCESS_NOTIFICATION_POLICY" />
tobob commented 6 years ago

checked on both:

tobob commented 6 years ago

btw, iOS notification works always

fryossi commented 6 years ago

@tobob It seems that you're using the action for GCM. try to replace with <action android:name="com.google.firebase.MESSAGING_EVENT"/>

tobob commented 6 years ago

@fryossi I did change <action android:name="com.google.android.c2dm.intent.RECEIVE"/> into <action android:name="com.google.firebase.MESSAGING_EVENT"/> but still Im don't get notification when app is off

qmegas commented 6 years ago

Anyone succeeded to solve that problem?

Rajat421 commented 6 years ago

i am facing the same issue ...

WonderDev21 commented 6 years ago

i am facing the same issue ...

guilleHein commented 6 years ago

same issue here

akyker20 commented 6 years ago

same issue

Rajat421 commented 6 years ago

@akyker20 what are you using for push notification, fcm or firebase

Rajat421 commented 6 years ago

@akyker20 I am using intercom in my project and able to get push notification. I am taking help from react-native-firebase. What I did was created a CustomFCMMessageService.java in same directory where mainApplication.java is present.

`package com.xxx.xxx;

import java.util.Map; import android.util.Log; import com.google.firebase.messaging.RemoteMessage; import com.webengage.sdk.android.WebEngage; import io.invertase.firebase.messaging.RNFirebaseMessagingService; import io.intercom.android.sdk.push.IntercomPushClient;

public class CustomFCMMessageService extends RNFirebaseMessagingService { private static final String TAG = "CustomFCMMessageService";

private final IntercomPushClient intercomPushClient = new IntercomPushClient();

@Override

public void onMessageReceived(RemoteMessage remoteMessage) {
    Map message = remoteMessage.getData();

    Log.d("MessageReceived", "" + message);
    //Webengage

    if (message != null) {
        if (intercomPushClient.isIntercomPush(message)) {
            Log.d(TAG, "Intercom message received");
            intercomPushClient.handlePush(getApplication(), message);
        }  else {
            super.onMessageReceived(remoteMessage);
            Log.d(TAG, "NATIVE message received");

        }
    }
}

}

` I am using Firebase messaging service to detect push notification.

then in AndroidManifest.xml

add this ` <service android:name=".CustomFCMMessageService" // replacing firebase messaging service as suggested by doc android:enabled="true" android:exported="true">

    </service>

`

Hope this will help :)

vvusts commented 5 years ago

@tobob did you solve your issue somehow? I have the same problem like you. @Rajat421 I created file CustomFCMMessageService same like you and when I did this I started to receive notification on android. But still can't get notification when app is killed instead when debug I get this error: No Channel found for pkg=com.myapp, channelId=intercom_new_chats_channel And this work in all cases but not when app is killed only on adnroid?