ad_728x90

2015年9月22日 星期二

How to integrate Push Notification/GCM + Admin Panel in your Existing APP

How to integrate Push Notification/GCM + Admin Panel in your Existing APP


Required java files for GCM integration Copy following file to your project
  1. News.Java  => used for internal news notification adapter
  2. GcmBrodcastRecive.java => the brodcast receiver for GCM notification receiver.
  3. GCM_Config.java=> the configuration file. contains your gcm SENDER_ID, SERVER_PATH. etc.
  4. DatabaseHandler.java => database handler to save news notifications offline.
  5. DialogeNotice.java => the dialog notification activity styled as dialog.
  6. CustomWebView.java => our own custom web activity for web notification
  7. Api_Web.java => helper class to use with network related stuff to register on to our server [use third party library : loopj asynctask]
  8. NoZoomControllWebView.java => our custom webview.Inserting Librariescopy this lib into your project -> libs folder
1. =>android-async-http-1.4.3.jar : used to call network related stuff . [Like sending our email with registration on our server] =>universal-image-loader-1.9.2.jar:used to load images from web into a imageview asyncronizly
Now from MainActivity.java file 
Copy following  functions to your main launcher activity [the activity which starts your App]
1.  isNetworkAvailable – return true/false according to your internet connectivity
2. checkPlayService – return true if google play serviece is available in the device [required for gcm serviece to work] -return false if not present
3. getAppVersion -return the current build code of app.
4. getRegistrationId -return the unique registration id for the app if stored previously by us. – otherwise return empty string
5. storeRegistrationId – store the current registraation id as per current app version. will be used to sync when app updated to newer version.
6. showAlert – show’s the alert dialog with given title and messege. will be use for notifying the user about progress or result of registration.
7.  registerInBackground – this method creates async task apart from main thread and generate unique registration gcm_id for app. and pass this information to backend via another method.
8. sendRegistrationIdToBackend – this method call the server API to store your unique gcm_id to your backend. and also update sharedpreference to avoid future request to our server.
Registering the receiver and serviece – Copy GcmBroadcastReceiver and GcmIntentService   to your project . you should change the package according to your project.
Chaniging the AndroidManifest file –
1. Add this permissions :
 <uses-permission android:name="android.permission.WAKE_LOCK" />
 <!-- This app has permission to register and receive data message. -->
 <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
 <!-- Permission to vibrate -->
 <uses-permission android:name="android.permission.VIBRATE" />
 <!-- Creates a custom permission so only this app can receive its messages. -->
 <permission
 android:name="com.icanstudioz.gcmintegration.permission.C2D_MESSAGE"
 android:protectionLevel="signature" />
 <uses-permission android:name="seradio.rfix.com.gcm.permission.C2D_MESSAGE" />
 <uses-permission android:name="android.permission.INTERNET" />
 <uses-permission android:name="android.permission.READ_PHONE_STATE" />
2. Adding Activity , Services, and Brodcaster
 <activity
 android:name="radioklub.sekhontech.com.gcm.DailogeNotice"
 android:theme="@style/AppTheme.Dialog" >
</activity>

 <activity
 android:name="radioklub.sekhontech.com.gcm.CustomeWebView">
 </activity> 
 <activity 
 android:name="com.google.android.gms.ads.AdActivity"
 android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />
<receiver android:name="radioklub.sekhontech.com.gcm.GcmBroadcastReceiver" 
 android:permission="com.google.android.c2dm.permission.SEND" >
 <intent-filter>
 <!-- Receives the actual messages. -->
 <action android:name="com.google.android.c2dm.intent.RECEIVE" />
 <category android:name="radioklub.sekhontech.com.gcm" />
 </intent-filter>
</receiver>
<service android:name="radioklub.sekhontech.com.gcm.GcmIntentService" />
3. Adding Metatag of google play service
Add this under <application tag
 <meta-data
 android:name="com.google.android.gms.version"
 android:value="@integer/google_play_services_version" />
Adding values and styles
copy      res -> values -> string.xml
and        res-> values ->style.xml
data
and paste to your relevant xml files. [do not overwrite this files]
Adding drawables and layouts
copy      res -> drawables
and        res-> layouts
Posted on September 2, 2015 in Uncategorized

COMMENTS HAVE BEEN DISABLED FOR THIS POST [文章的評論已被禁用]

Ratings and Recommendations by outbrain