LP-Messaging / Android-Messaging-SDK

LivePerson Android Messaging SDK
https://www.liveperson.com
28 stars 24 forks source link

Not receiver the Notifications #40

Closed zstartw closed 6 years ago

zstartw commented 6 years ago

I followed the developer liverperson web.and configured my liverperson below:

configured AndroidManefest.xml

<service android:name=".support.gcm.MyFirebaseMessagingService">
            <intent-filter>
                <action android:name="com.google.firebase.MESSAGING_EVENT"/>
            </intent-filter>
        </service>
        <!-- [END firebase_service] -->
        <!-- [START firebase_iid_service] -->
        <service android:name=".support.gcm.MyFirebaseInstanceIDService">
            <intent-filter>
                <action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
            </intent-filter>
        </service>

MyFirebaseInstanceIDService.java

public class MyFirebaseInstanceIDService extends FirebaseInstanceIdService {

    private static final String TAG = "MyFirebaseIIDService";

    /**
     * Called if InstanceID token is updated. This may occur if the security of
     * the previous token had been compromised. Note that this is called when the InstanceID token
     * is initially generated so this is where you would retrieve the token.
     */
    // [START refresh_token]
    @Override
    public void onTokenRefresh() {
        // Get updated InstanceID token.
        String refreshedToken = FirebaseInstanceId.getInstance().getToken();
        LogUtils.d(TAG, "Refreshed token:" + refreshedToken);

        //send the token to liveperson
        LivePerson.registerLPPusher(LiverPersonUtil.BRAND_ID, LiverPersonUtil.APP_ID, refreshedToken);

        // If you want to send messages to this application instance or
        // manage this apps subscriptions on the server side, send the
        // Instance ID token to your app server.
        //        sendRegistrationToServer(refreshedToken);
    }
    // [END refresh_token]

    /**
     * Persist token to third-party servers.
     * <p>
     * Modify this method to associate the user's FCM InstanceID token with any server-side account
     * maintained by your application.
     *
     * @param token The new token.
     */
    private void sendRegistrationToServer(String token) {

    }
}

In my Application init the liveperson

 LivePerson.initialize(this, new InitLivePersonProperties(LiverPersonUtil.BRAND_ID, LiverPersonUtil.APP_ID, new InitLivePersonCallBack() {
            @Override
            public void onInitSucceed() {
                Log.d(TAG, "onInitSucceed: ");

                LiverPersonUtil.handleGCMRegistration(instance);

                ConsumerProfile profile = new ConsumerProfile
                        .Builder()
                        .setNickname("test")
                        .setFirstName("zhengwu")
                        .setLastName("wu")
                        .setPhoneNumber("110")
                        .build();
                LivePerson.setUserProfile(profile);
            }

            @Override
            public void onInitFailed(Exception e) {
                Log.d(TAG, "onInitFailed: ");
            }
        }));

LiverPersonUtil.java

 public static void handleGCMRegistration(Context ctx) {
        Intent intent = new Intent(ctx, MyFirebaseInstanceIDService.class);
        ctx.startService(intent);
    }

but I can not received the notications. the method onMessageReceived in FirebaseMessagingService not run.please help me

shaymLP commented 6 years ago

Looks like your code is missing the 'Firebase RegistrationIntentService', here is a simple example:

public class FirebaseRegistrationIntentService extends IntentService {   public static final String TAG = FirebaseRegistrationIntentService.class.getSimpleName();   public FirebaseRegistrationIntentService() {       super(TAG);   }  @Override   protected void onHandleIntent(Intent intent) {       Log.d(TAG, "onHandleIntent: registering the token to pusher");       String token = FirebaseInstanceId.getInstance().getToken();       // Register to Liveperson Pusher       String account = "82055668";       String appID = "com.shaym.sdk28";       LivePerson.registerLPPusher(account, appID, token);   }}
--

And declaring it in the manifest file as well:

        <service
            android:name=".push.fcm.FirebaseRegistrationIntentService"
            android:exported="false">
        </service>

Make sure the handleGCM starts the correct service:

private void handleGCMRegistration(Context ctx) {
   Intent intent = new Intent(ctx, FirebaseRegistrationIntentService.class);
   ctx.startService(intent);
}
zstartw commented 6 years ago

@shaymLP Thank you for your reply, I tried to add these configurations to my project, but still no effect. This is my background data configuration, I am not sure there is no set error. screenshot from 2017-11-21 15-36-48 Is there any other way to debug notice?

zstartw commented 6 years ago

Notifications sent via the Firebase console can be received, but messages from Liveperson can not be found

parrishsteve commented 6 years ago

Hi zstartw, Do you have more than one entry for 'GearBest-Test' under your configured apps on the LP dashboard? If so make sure that all apps are uniquely named.

parrishsteve commented 6 years ago

Also, make sure you are sending the correct application name when you register your token with LP. For example you do...

LivePerson.registerLPPusher(LiverPersonUtil.BRAND_ID, LiverPersonUtil.APP_ID, refreshedToken);

Is 'LiverPersonUtil.APP_ID' set to "GearBest-Test"?

zstartw commented 6 years ago

@parrishsteve,I checked out the preparation of the project, and did not find any difference, this is my id set.

public final static String BRAND_ID = "70088615";
public final static String APP_ID = "ed1d95ea-63e7-45b7-8f11-1a87173b7536";

I am very confused now this notification function, do not know when to receive this notice.

orenkatz commented 6 years ago

@zstartw the App ID should be bundle name, "GearBest-Test" in your case You can check this documentation for more information on how to implement push notification in Android https://developers.liveperson.com/android-implementation-guide.html