Follow

Install the SDK for Android

Install the SDK for Android

The Kahuna SDK for Android currently supports Android 2.2+ devices (API level 8 and above) and requires internet to be added as a permission to your application.

Follow the steps below to integrate Kahuna with your app.

    1. Install the Kahuna SDK. Android SDK provides a cloud-based SDK repository that you can use from gradle. Using this repository, you can build your apps in Android Studio without having to download the Kahuna SDK to your computer.

 

      1. Open the project for your app, then open the Project Window.
      1. Open the build.gradle file for your project. For example, build.gradle (Project: your_project_name)
      2. In the allprojects section of the build.gradle file, add the following line.

        maven { url "https://kahuna.github.io/kahuna-android/sdk" }
      3. In the buildscript section of the build.gradle file, add the following line under dependencies.

        classpath 'com.google.gms:google-services:3.0.0'

        The following shows an example of a build.gradle file.

        buildscript {
           repositories {
               maven { url "https://kahuna.github.io/kahuna-android/sdk" }
               jcenter()
           }
           dependencies {
               classpath 'com.android.tools.build:gradle:2.2.0'
               classpath 'com.google.gms:google-services:3.0.0'
               // NOTE: Do not place your application dependencies here; they belong
               // in the individual module build.gradle files
           }
        }
        
        allprojects {
           repositories {
               maven { url "https://kahuna.github.io/kahuna-android/sdk" }
               jcenter()
           }
        }
        
      4. Open the build.gradle file for the module that contains your app. For example, build.gradle (Module: your_app_module_name). In most cases, your_app_module_name is app.

      5. For Firebase users, in the dependencies section of build.gradle, add the following line.

        api 'com.kahuna.sdk:kahuna:3.2.+'
        api 'com.android.support.constraint:constraint-layout:1.0.2'

        Alternatively, for Firebase users, to use the Kahuna Marketplace SDK, in the dependencies section of build.gradle, add the following line.

        api 'com.kahuna.marketplace.sdk:kahuna:4.0.+'
        api 'com.android.support.constraint:constraint-layout:1.0.2'
      6. Sync your project to apply the changes.

 

  1. Add the Android Support Library to your project. Follow the instructions for your environment (Eclipse or Android Studio) in the Support Library Setup topic on the Android Developer website.

    Note: Kahuna requires Android Support Library version 4.

  2. Set up Google Play services for your project. Follow the instructions for your environment (Eclipse with ADT or Android Studio) in the Setting Up Google Play Services topic on the Google Developers website.

    Kahuna requires the following components of Google Play services:

    • Google Location, Activity Recognition, and Places: com.google.android.gms:play-services-location:10.0.1

    Note: If you perform a custom installation of Google Play services in Android Studio, you must include the required components in your build; otherwise, your app might crash. Google does not allow you to customize the installation of Google Play services in Eclipse with ADT.

  3. Add the permission android.permission.INTERNET to your manifest so that your app has permission to access the Internet.

    <uses-permission android:name="android.permission.INTERNET" />

Now that you have installed the SDK, add user credentials. Follow the steps in Add User Credentials.

Upgrade the SDK for Android from 2.x to 3.x

Development on the KahunaSDK 2.x has stopped. We strongly recommend that all customers upgrade their Android apps to use Firebase which is supported in the KahunaSDK 3.x. Applications written using Firebase and targetting Android O provide better battery life through optimizations that are not possible with GCM.

Follow the steps below to upgrade your application to use Firebase and the KahunaSDK 3.x with your app.

Instructions for Upgrading from SDK 2.x (GCM) to SDK 3.x (Firebase)

Kahuna SDK 3.0 introduces the use of Firebase for push notifications instead of GCM.

Follow these steps to upgrade to Kahuna SDK 3.x from Kahuna SDK 2.x.

  1. Go to https://firebase.google.com/docs/android/setup and follow the steps in the Manually add Firebase subsection of the Add Firebase to your app section.
  2. From the Firebase console, download the google-services.json file.

  3. Add google-services.json to the root folder of your Android app.
  4. Update the GCM/FCM Server Key in Kahuna.

    1. On the top bar of the Kahuna application, click , then click Settings to open the Configuration tab of the Settings page.
    2. In the Push Authorization section, update the Android GCM/FCM Server Key with your Firebase Cloud Messaging Server Key.

      You may also provide the FCM Key to Kahuna Customer Support.

  5. Update your gradle files:
    1. In the root level gradle file, add the following code.

      buildscript {
          // ...
          dependencies {
              // ...
              classpath 'com.google.gms:google-services:3.0.0'
          }
      }
    2. In the app level gradle file, replace this code:

      apply plugin: 'com.android.application'
      
      android {
        // ...
      }
      
      dependencies {
         //...
         compile 'com.google.android.gms:play-services:+'
         compile 'com.kahuna.sdk:kahuna:2.+'
         //...
      }

      with this code:

       apply plugin: 'com.android.application'
      
      android {
        // ...
      }
      
      dependencies {
        // ...
        compile 'com.google.android.gms:play-services-location:10.0.1'
        compile 'com.google.firebase:firebase-messaging:10.0.1'
        compile 'com.kahuna.sdk:kahuna:3.+'
       
        // Getting a "Could not find" error? Make sure you have
        // the latest Google Repository in the Android SDK manager
      }
      
      // ADD THIS AT THE BOTTOM
      apply plugin: 'com.google.gms.google-services'
  6. Update the AndroidManifest.xml file.

    Remove the following permissions:

    <permission
       android:name="com.kahuna.sample.permission.C2D_MESSAGE"
       android:protectionLevel="signature" />
    
    <uses-permission android:name="com.kahuna.sample.permission.C2D_MESSAGE" />
    
    <!-- App receives GCM messages. -->
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
    <!-- GCM requires a Google account. -->
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <!-- Keeps the processor from sleeping when a message is received. -->
    <uses-permission android:name="android.permission.WAKE_LOCK" />

    Replace this code block:

    <!-- REQUIRED: Kahuna's push requires the receivers and service -->
    <receiver android:name="com.kahuna.sdk.KahunaCoreReceiver" />
    <receiver
       android:name="com.kahuna.sdk.KahunaPushReceiver"
       android:permission="com.google.android.c2dm.permission.SEND">
       <intent-filter>
           <action android:name="com.google.android.c2dm.intent.RECEIVE" />
           <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
    
           <!-- MODIFICATION: Replace "com.kahuna.sample" with your package -->
           <category android:name="com.kahuna.sample" />
       </intent-filter>
    </receiver>
    
    <service android:name="com.kahuna.sdk.KahunaPushService" />
    <!-- END of Kahuna's push requirements -->
    <!-- Below is for custom push receiver -->
    <receiver android:name="[CUSTOM_PUSH_RECEIVER_REFERENCE]" /> 

    with this code:

    <!-- REQUIRED: Kahuna's push requires the receivers and service -->
    
    <receiver android:name="com.kahuna.sdk.KahunaCoreReceiver" />
    <service
       android:name="com.kahuna.sdk.KahunaInstanceIDListenerService">
       <intent-filter>
           <action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
       </intent-filter>
    </service>
    <service
       android:name="com.kahuna.sdk.KahunaFcmListenerService">
       <intent-filter>
           <action android:name="com.google.firebase.MESSAGING_EVENT" />
       </intent-filter>
    </service>
    <!-- Below is for custom push receiver -->
    <receiver android:name="[CUSTOM_PUSH_RECEIVER_REFERENCE]" />
    
    <!-- END NEW KAHUNA -->

 

Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request

Comments