參觀我的【 伊生活小舖】

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. => the brodcast receiver for GCM notification receiver.
  3.> the configuration file. contains your gcm SENDER_ID, SERVER_PATH. etc.
  4. => database handler to save news notifications offline.
  5. => the dialog notification activity styled as dialog.
  6. => our own custom web activity for web notification
  7. => helper class to use with network related stuff to register on to our server [use third party library : loopj asynctask]
  8. => 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 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="" />
 <!-- Permission to vibrate -->
 <uses-permission android:name="android.permission.VIBRATE" />
 <!-- Creates a custom permission so only this app can receive its messages. -->
 android:protectionLevel="signature" />
 <uses-permission android:name="" />
 <uses-permission android:name="android.permission.INTERNET" />
 <uses-permission android:name="android.permission.READ_PHONE_STATE" />
2. Adding Activity , Services, and Brodcaster
 android:theme="@style/AppTheme.Dialog" >

 android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />
<receiver android:name="" 
 android:permission="" >
 <!-- Receives the actual messages. -->
 <action android:name="" />
 <category android:name="" />
<service android:name="" />
3. Adding Metatag of google play service
Add this under <application tag
 android:value="@integer/google_play_services_version" />
Adding values and styles
copy      res -> values -> string.xml
and        res-> values ->style.xml
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


Ratings and Recommendations by outbrain