##Installation Add the following to your app level build.gradle
dependencies {
.
.
compile 'com.orchotech.priyamsaikia.lib-pushez:pushez:beta.1.0.3'
}
https://developers.google.com/cloud-messaging/android/start
1. Initialise PushEZ with Google Sender ID, Register Device to get Google Cloud Device Registration ID
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);
}
@Override
public void onRegistrationComplete(String registrationId) {
Log.d("take your token", registrationId);
}
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"));
}
}
<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
@Override
public void onPushReceived(Bundle bundle) {
Log.d("my receiver", bundle.getString("message"));
}
Thanks !
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.