Skip to content
This repository has been archived by the owner on Apr 28, 2022. It is now read-only.

The easiest way to implement GCM

Roman Savin edited this page May 14, 2015 · 2 revisions

Add the following peace of code in your Application.onCreate() method:

Configuration.Builder configBuilder = new Configuration.Builder()
                .addProviders(new GCMProvider(this, GCM_SENDER_ID)) //Your sender ID.
                .setEventListener(new SimpleEventListener() {
                    @Override
                    public void onMessage(Context context, String providerName, Bundle extras) {
                        //Show notification
                    }

                    @Override
                    public void onRegistered(Context context, String providerName, String registrationId) {
                        //Send registration id to your 3rd party server.
                    }
                });

OPFPush.init(this, configBuilder.build());
OPFPush.getHelper().register();

Add dependency and update your AndroidManifest.xml file as described on this page.

It's all you have to do for simple using of GCM.