Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to implement Urban Airship api in android to send gcm notifications ?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 340
    Comment on it

    Urban Airship api provides you better way to implement push notifications and also provide you facility to send messages on production without sending it to live users so you can even test in production phase.

    This api supports gcm and amazon push notification services.

    Here is the example to show how can we send push notifications using GCM services :

    1 . Include urban maven repository and dependencies like this :

       

    repositories {
        maven {
            url  "https://urbanairship.bintray.com/android"
        }
    }
    
    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        compile 'com.android.support:appcompat-v7:23.3.0'
        compile 'com.android.support:design:23.3.0'
    
        compile 'com.urbanairship.android:urbanairship-sdk:6.2.+'
        compile 'com.android.support:cardview-v7:23.3.0'
    
        compile 'com.google.android.gms:play-services-location:8.4.0'
        compile 'com.google.android.gms:play-services-gcm:8.4.0'
    }

     Please note that sometimes you can face error  like no gcm service enabled for messaging like this so change the 8.4.0 to 7.5.0 .

    2. Verify the applicationId :

    defaultConfig {
        applicationId "com.example.rohitpuri.myurbanapplication"
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }

    3. Now go to urban web ui to create and configure your android app :
        
      Go to https://go.urbanairship.com and create new app then fill form to enter app name, icon, production status, select platform like android or ios etc and save form.

    4. Download your airoushconfig.properties file and save it to src/main/assets folder.

    Note - also remember to add sender id in this config file , this sender id will generate from gcm dashboard.

    5. Now create a class extends Application and in onCreate create airship class to enable user notifications in app like this :

    public class CustomApplication extends Application  {
    
        @Override
        public void onCreate() {
            super.onCreate();
    
            UAirship.takeOff(this, new UAirship.OnReadyCallback() {
                @Override
                public void onAirshipReady(UAirship airship) {
    
                    // Enable user notifications
                    airship.getPushManager().setUserNotificationsEnabled(true);
                }
            });
        }
    }

    6. Add the GCM Sender ID airshipconfig.properties

    # GCM Sender ID
    gcmSender = #########

    7. build your project then from urban web ui there is an option to send message where you can enter text and can send push notification messages to registered applications.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: