Fernando
Fernando

Reputation: 119

Implement push notification server in php

This is my first post, sorry my English

Hello every one. I am a new programmer in PHP and i would like to use Zend Mobile Framework to implement my push notificator server.

I'm searching how to implement the tomcat project used in

http://developer.android.com/guide/google/gcm/demo.html

but written in PHP.

In the code most below I written the used sources. When I call the submit button, always have response with InvalidRegistration error.

Can anyone see where the error?

Thank You very much

http://pastebin.com/MauzLX71

Upvotes: 0

Views: 6889

Answers (2)

mwillbanks
mwillbanks

Reputation: 1011

One of the things that you are likely having happen here is the following:

  • Your code is actually processing and attempting to send a message prior to your call of sendPush which may be causing part of the issue.
  • Did you sign up for an API key and replace that portion in the code?
  • In the demo client application; it shows how to actually leverage the registration; see my comment on the following GitHub issue: https://github.com/mwillbanks/Zend_Mobile/issues/16
    • Your server needs to have the registration id from the device; this is likely what you do not have.
    • One way of getting the registration ID is on the onRegistered call inside the client app, do a Log.i("MY_APP_TAG", regId); then look at the logcat output.

Android Example

public class GCMIntentService extends GCMBaseIntentService {

    public GCMIntentService() {
        super(Constants.SENDER_ID);
    }

    @Override
    protected void onRegistered(Context context, String regId) {
        Log.i("MY_APP_TAG", "Registered: " + regId);
    }

    @Override
    protected void onUnregistered(Context context, String regId) {
        // write a call here to send the regId to your server and unregister it
    }

    @Override
    protected void onMessage(Context context, Intent intent) {
        Log.i("MY_APP_TAG", "Received message!");
        // grabbing data looks like the following; the assumption
        // is title is part of the data string.
        String title = intent.getExtras().getString("title");
    }

}

*Zend_Mobile_Push_Gcm Example*

See the updated link (http://pastebin.com/NhrD5N6i) I provided of your pasted code; you will want to use the registration ID above in the textbox.

Upvotes: 0

yugidroid
yugidroid

Reputation: 6690

According with Android GCM's architectural overview you have an invalidRegistration error when:

Invalid Registration ID Check the formatting of the registration ID that you pass to the server. Make sure it matches the registration ID the phone receives in the com.google.android.c2dm.intent.REGISTRATION intent and that you're not truncating it or adding additional characters. Happens when error code is InvalidRegistration.

Check the official GCM documentaion here, please.

Upvotes: 1

Related Questions