Message Boards

Push Notification On Liferay 7

reda zejli, modified 7 Years ago.

Push Notification On Liferay 7

New Member Posts: 10 Join Date: 9/1/16 Recent Posts
I am trying to build an Android app using liferay mobile sdk and liferay screens and I want to implement Push Notification.
I have followed the steps in the tuotrial :https://www.youtube.com/watch?v=4LjutX0dcRw&feature=youtu.be.

And i have arrived to a step where I find my device registered in my liferay Portal in device section But still dont receive notifications.

This is my Activity Code .What Am i missing?? Please any help :

public class MainActivity extends PushScreensActivity {

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

Session session = new SessionImpl("xxxxxxxxxxxxxxxxxxxxxxxxxxx", new BasicAuthentication("xxxxxx", "xxx"));

try {
Push.with(session).register(this, "xxx");
Push.with(session).onPushNotification(new Push.OnPushNotification() {
@Override
public void onPushNotification(JSONObject pushNotification) {
System.out.println("NOtification !"+pushNotification);
}
});
} catch (Exception e) {
System.out.println(" Error While Registring!");
e.printStackTrace();
}
}

@Override
protected Session getDefaultSession() {
Session session = new SessionImpl("xxxxxxxxxxxxxxxxxxxxx", new BasicAuthentication("rxxxx", "xxx"));

return session;
}

@Override
protected void onPushNotificationReceived(JSONObject jsonObject) {
System.out.println("Receiving :"+jsonObject);
}

@Override
protected void onErrorRegisteringPush(String message, Exception e) {
System.out.println("Problem Registration");
}

@Override
protected String getSenderId() {
return "xxxxxxxxxxxx";
}
thumbnail
Javier Gamarra, modified 7 Years ago.

RE: Push Notification On Liferay 7

Expert Posts: 348 Join Date: 2/12/15 Recent Posts
Have you registered the service and broadcast receiver?

There is a working example here: https://github.com/liferay/liferay-screens/tree/develop/android/samples/pushnotifications
reda zejli, modified 7 Years ago.

RE: Push Notification On Liferay 7

New Member Posts: 10 Join Date: 9/1/16 Recent Posts
Thank you for your reply .I think my problem is coming from the gcm registration because everything seems to be fine in android and liferay portal. I have set all the code given.
But the problem is on gcm because I have tested from another console with the token and the key given but I got "Error: Received error code 401 from GCM Service". So I need to know how must be registered the App because when I go to google console I find myself redirected to Firebase Console and even If I registre with the old Gcm service I don't get the authorization.
So what's the right way to register the app to be well configured for using Liferay.
Thank you.
thumbnail
Javier Gamarra, modified 7 Years ago.

RE: Push Notification On Liferay 7

Expert Posts: 348 Join Date: 2/12/15 Recent Posts
Uhm, the old code should work even with firebase rolling around (still uses GCM behind)

Can you try your sender Id in the example code or attach a sample of your code?
reda zejli, modified 7 Years ago.

RE: Push Notification On Liferay 7

New Member Posts: 10 Join Date: 9/1/16 Recent Posts
In fact ,I have the device registered in my portal with the token but nothing happen after when I try to send somthing from test tab.
What can be the possible causes and How can I get more logs.
Also I want to understand what should be done in liferay-plugin-package.properties file because I didn't touch this file because It's supposed to be edited when "push notification ce" is installed.

I can't try with the sender id in the example code because I don't have the api key to give to my portal.
thumbnail
Javier Gamarra, modified 7 Years ago.

RE: Push Notification On Liferay 7

Expert Posts: 348 Join Date: 2/12/15 Recent Posts
If the device is registered in the portal it should be either the receiver/service or some permission (did you set WAKE_LOCK?).

My suggestion was use the push demo app with your senderId/server + API key and check that all the keys are right.

You can send me the code by email to see if something is missing.