Skip to content

priyamsaikia/PushEZ

Repository files navigation

PUSHEZ - Push Easy

PushEZ is a library which makes it really easy to implement Google Cloud Messaging (Push Notification Messaging). All you have to do is follow the following three steps! This library completely handles the device registration part and push message receiving part. Thereby, making it extremely easy for developers to use GCM. You can chose to handle the messages as you want (eg, sending notification, or saving it in database, etc)

##Installation Add the following to your app level build.gradle

dependencies {
		.
		.
	    compile 'com.orchotech.priyamsaikia.lib-pushez:pushez:beta.1.0.3'
	}

GET STARTED : Get Your Sender ID and (note the Server API key) in the link below

https://developers.google.com/cloud-messaging/android/start

1. Initialise PushEZ with Google Sender ID, Register Device to get Google Cloud Device Registration ID

MyActivity.java
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        PushEZ.initPushEZ(this, "your_sender_id");
        PushEZ.getRegistrationId(this);
        PushEZ.registerRegistrationListener(this);
        
    }


    @Override
    protected void onResume() {
        super.onResume();
        PushEZ.registerPushEZTokenReceiver(this);
    }

    @Override
    protected void onPause() {
        super.onPause();
        PushEZ.unregisterPushEZTokenReceiver(this);
    }

2. Save the Google Cloud Device Registration ID

MyActivity.java

2. a) implement PushEZ.RegistrationListener in the activity

2. b) implement method onRegistrationComplete(String registrationId)

    @Override
    public void onRegistrationComplete(String registrationId) {
        Log.d("take your token", registrationId);
    }

3. Receive Push Notifications

3 a) In the BroadCastReceiver, implement PushReceivedUtil.PushEZListener

3 b) Implement method

public class MyReceiver extends BroadcastReceiver implements PushReceivedUtil.PushEZListener {
    private PushReceivedUtil.PushEZListener  mPushEZListener;
    @Override
    public void onReceive(Context context, Intent intent) {
        mPushEZListener = this;
        PushReceivedUtil.registerListener(mPushEZListener);
    }

    @Override
    public void onPushReceived(Bundle bundle) {
        Log.d("my receiver", bundle.getString("message"));
    }
}

4. Register the receiver in the AndroidManifest.xml

AndroidManifest.xml
<receiver android:name=".MyReceiver">
            <intent-filter>
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            </intent-filter>
</receiver>

To check if the app is working well,

a) Note the token ID or registration ID from console, that you receive in the method

public void onRegistrationComplete(String registrationId) {
        Log.d("take your token", registrationId);
    }

b) Note the Server API Key from Google Developers' Console
c) Visit

enter your key and registration id in the provided form, enter message and check your console to know if you have received the message (or generate a notification in this method

@Override
    public void onPushReceived(Bundle bundle) {
        Log.d("my receiver", bundle.getString("message"));
    }

Thanks !

LICENSE

Copyright 2016 Priyam Saikia

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

About

A library that makes it very easy to implement Google Cloud Messaging in Android Apps .

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages