How to receive push notification even if the app is not running

Hello,
I’m facing issue in receiving notification when the app is not running i.e if i quit the application. If the application is running then, easily ill get the push notification however if i quit the app, i wont get any notification. Please help.
Here is my receiver in manifest file and the code.

<intent-filter>


<category android:name=“com.kidzvideos” />
</intent-filter>
</receiver>

Here how i’m registering the device and subscribing for message. This i’m doing it in my mainactivity.java

class.public void RegisterForPushNotification()
{
Backendless.Messaging.registerDevice(mProjectNumber, mChannelName, new AsyncCallback<Void>() {
@Override
public void handleResponse(Void aVoid) {
Toast.makeText(BaseYoutubeActivity.this, “Device Registered succesfully”, Toast.LENGTH_LONG).show();
}
@Override
public void handleFault(BackendlessFault fault) {
Toast.makeText(BaseYoutubeActivity.this, fault.getMessage(), Toast.LENGTH_LONG).show();
}
});

Backendless.Messaging.subscribe( mChannelName,
new AsyncCallback<List<Message>>() {
public void handleResponse(List<Message> response) {
Toast.makeText(BaseYoutubeActivity.this, “Notification arrived successfully”, Toast.LENGTH_LONG).show();
for (Message message : response) {
String publisherId = message.getPublisherId();
Object data = message.getData();
}
}
public void handleFault(BackendlessFault fault) {
Toast.makeText(BaseYoutubeActivity.this, fault.getMessage(), Toast.LENGTH_SHORT).show();
}
},
new AsyncCallback<Subscription>()
{
public void handleResponse( Subscription response )
{
subscription = response;
}
public void handleFault( BackendlessFault fault )
{
Toast.makeText( BaseYoutubeActivity.this, fault.getMessage(), Toast.LENGTH_SHORT ).show();
}
}
);
}

Ramesh,

In order to receive push notifications, you should implement an Android service class which would handle all the logic of push notifications. It is essentially the same code that we have in our BackendlessBroadcastReceiver:
https://github.com/Backendless/Android-SDK/blob/master/src/com/backendless/push/BackendlessBroadcastReceiver.java

Suppose the service class is “com.foo.MyGCMService”. Then you should create your own broadcast receiver that would have the following code:

public class GCMReceiver extends WakefulBroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
ComponentName comp = new ComponentName(context.getPackageName(), com.foo.MyGCMService.class.getName());
startWakefulService(context, (intent.setComponent(comp)));
setResultCode(Activity.RESULT_OK);
}
}

Hi,

As you told i struggled lot, i changed my code like, i created my own listener

public class GCMReceiver extends WakefulBroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(context, “Notification came”, Toast.LENGTH_LONG).show();
}
}
Then i updated my manifest file like below, still only device is registering but i’m not getting notification event

<receiver android:name=“droid.backednlessgcm.GCMReceiver” android:permission=“com.google.android.c2dm.permission.SEND”>
<intent-filter>


<category android:name=“droid.backednlessgcm”/>
</intent-filter>
</receiver>

Please help, i tried to implement like standard Google cloud messaging service, its not at all working :frowning:

Note: Does it require to subscribe for Backendless.Messaging.subscribe always mandatory?

Have you created a Service implementation?

I have not created, beacause some of the GitHub projects hosted by you, do not have any services implemented explicitly.

I have sample code, which has got GCM working, however in that i’m using localhost and sending message, but through backendless i’m not getting how to do?.

Only difference i’m finding is, backendless do have got Backendless.Messaging.subscribe, call. If i do it works well when the application is running, if i kill its not coming to receiver.

Do you have any sample latest working example hosted in github, so that i can try. i’m struggling from 3 days, please help me with any sample which is working on backendless.

Thanks

@Mark, Could you please assist me/us, what is the issue. I have seen many people in this forum are facing the same issue. But they are all trying multiple trial and error to solve the issue.

Please assist me also, if possible, can you update Git with latest example, or you can post hint for me to resolve the issue. I’m happy to publish an article on backendless push notification. It should be really useful for others who use the backendless.

Thanks

Hi Ramesh,

This functionality is currently being implemented in Android SDK, so we shall notify you as soon as it is available for use.

The documentation has been updated. Please see the “Manifest Configuration” section at:

https://backendless.com/documentation/messaging/android/messaging_push_notification_setup_androi.htm