0

The basic architecture of the push functionality that I am trying to create is

1) I would get the phone id and store it in my db

2) Only when something happened on the server I would try to create a push message

So I do not need the part where the app tries to call the server to send it the message. I am wondering what should I extend in the Service class and what methods in it do I need to implement.

Also, am I able to get the device id and send that info to my server without using the server?

I am using Google cloud messaging.

Thanks!

2
  • Your question is very unclear. Lets go through this 1 point at a time. What do you mean by the phone id? Oct 16, 2012 at 20:16
  • @Kevin Bradshaw I meant the unique id of the phone to which I would send the push notification. It is the id that is needed to make the push notification. Does that help make it more clear? :)
    – Genadinik
    Oct 16, 2012 at 20:27

2 Answers 2

1

Ok, to get the registration ID for you phone you will need to do the following in an activity:

     import com.google.android.gcm.GCMRegistrar;
    private final static String SENDER_ID = "0001234567" // API Key, see comments;

    public class myActivity extends Activity {

        @Override
        public void onCreate(Bundle savedInstanceState) 
        {

            GCMRegistrar.checkDevice(this);
            GCMRegistrar.checkManifest(this);
            regId = GCMRegistrar.getRegistrationId(this);
 if (regId.equals("")) 
        {
             GCMRegistrar.register(this, SENDER_ID);
             Log.i(TAG,"registered a new ID");
        } 
        else 
        {
            Log.i(TAG,"Already Registered");
        }

your google reg will be contained in regId

You will need this in your Manifest:

<receiver
        android:name="com.google.android.gcm.GCMBroadcastReceiver"
        android:permission="com.google.android.c2dm.permission.SEND" >
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
            <category android:name="my.namespace" />
        </intent-filter>
    </receiver>

where my.namespace will equal whatever your package name is

3
0

You can follow this tutorial.. it uses the new GooglecloudMessaging API. And yes, you should extend IntentService cause the other ones deprecated now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.