掲示板

Receiving Push Notifications on Android.

thumbnail
7年前 に Peter Hancox によって更新されました。

Receiving Push Notifications on Android.

Junior Member 投稿: 45 参加年月日: 05/07/06 最新の投稿
Follow-on conversation with @nhpatt from GitHub Issue.

The code below came from following a tutorial on writing a Liferay push notification client. Perhaps it only went so far as registering a device, which I did actually achieve. I'd assumed that the "onPushNotificationReceived" method in the main activity would be called when a push notification was received. However, as I understand it from your last post on the GitHub issue, I also need a receiver and a service to receive the notification?

package com.dtc.liferaypushnotificationdemo;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.util.Log;

import com.liferay.mobile.android.auth.basic.BasicAuthentication;
import com.liferay.mobile.android.service.Session;
import com.liferay.mobile.android.service.SessionImpl;
import com.liferay.mobile.screens.context.LiferayScreensContext;
import com.liferay.mobile.screens.push.PushScreensActivity;

import org.json.JSONObject;

public class MainActivity extends PushScreensActivity {

private static final String TAG = "MainActivity";

@Override
protected void onCreate(Bundle savedInstanceState) {
    LiferayScreensContext.init(this);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
}

@Override
protected Session getDefaultSession() {
    Log.d(TAG, "getDefaultSession()");
    return new SessionImpl("http://host.domain.com:8080", new BasicAuthentication("xxxxxxx@xxxxxxxxx.xxx.xx", "xxxxxxxx"));
}

@Override
protected void onPushNotificationReceived(JSONObject jsonObject) {
    Log.d(TAG, "onPushNotificationReceived(JSONObject jsonObject)");
}

@Override
protected void onErrorRegisteringPush(String message, Exception e) {

}

@Override
protected String getSenderId() {
    return "xxxxxxxxxxxx";
}
}
thumbnail
7年前 に Javier Gamarra によって更新されました。

RE: Receiving Push Notifications on Android. (回答)

Expert 投稿: 348 参加年月日: 15/02/12 最新の投稿
Yes, in the push demo application there is an example of a simple receiver/service.
thumbnail
7年前 に Peter Hancox によって更新されました。

RE: Receiving Push Notifications on Android.

Junior Member 投稿: 45 参加年月日: 05/07/06 最新の投稿
Thanks. I'd just discovered those samples and begun building them. Bit more info than I had before.