Foren
Receiving Push Notifications on Android.
Peter Hancox, geändert vor 7 Jahren.
Receiving Push Notifications on Android.
Junior Member Beiträge: 45 Beitrittsdatum: 06.07.05 Neueste Beiträge
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?
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";
}
}
Javier Gamarra, geändert vor 7 Jahren.
RE: Receiving Push Notifications on Android. (Antwort)
Expert Beiträge: 348 Beitrittsdatum: 12.02.15 Neueste Beiträge
Peter Hancox, geändert vor 7 Jahren.
RE: Receiving Push Notifications on Android.
Junior Member Beiträge: 45 Beitrittsdatum: 06.07.05 Neueste Beiträge
Thanks. I'd just discovered those samples and begun building them. Bit more info than I had before.