Follow

Add User Credentials

Add User Credentials

User credentials help you customize campaigns to your users. After you determine what type of user credentials your app uses, follow the steps below. Check Before You Begin for information about user credentials.

To add user credentials

  1. In your Main Application class, incorporate the following lines.

    If you use only username, email, or user ID credentials for your users, add only these credentials. If you have additional user credentials you want to add for your users, such as Facebook ID or Twitter ID, add these credentials also. Make sure all user credentials are unique across all your users.

    import com.kahuna.sdk.EmptyCredentialsException; 
    import com.kahuna.sdk.IKahunaUserCredentials; 
    import com.kahuna.sdk.Kahuna; 
    import com.kahuna.sdk.KahunaUserCredentials;
    
    
    public class SampleApplication extends Application {
    
        @Override
        public void onCreate() {
            super.onCreate();
    
            Kahuna.getInstance().onAppCreate(this, "KAHUNA_SECRET_KEY", null);
            //TODO:Load your user credentials here
            IKahunaUserCredentials credentials = Kahuna.getInstance().createUserCredentials();
            credentials.add(KahunaUserCredentials.USERNAME_KEY, USERNAME_HERE);
            credentials.add(KahunaUserCredentials.EMAIL_KEY, EMAIL_HERE);
            credentials.add(KahunaUserCredentials.USER_ID_KEY, USER_ID_HERE);
            credentials.add(KahunaUserCredentials.FACEBOOK_KEY, FACEBOOK_ID_HERE);
            credentials.add(KahunaUserCredentials.TWITTER_KEY, TWITTER_ID_HERE);
            credentials.add(KahunaUserCredentials.LINKEDIN_KEY, LINKEDIN_ID_HERE);
            credentials.add(KahunaUserCredentials.GOOGLE_PLUS_ID, GOOGLE_PLUS_ID_HERE);
            credentials.add(KahunaUserCredentials.INSTALL_TOKEN_KEY, INSTALL_TOKEN_KEY_HERE);;			
            credentials.add(KahunaUserCredentials.MOBILE_NUMBER_KEY, MOBILE_NUMBER_HERE)
            try {
                Kahuna.getInstance().login(credentials);
            } catch (EmptyCredentialsException e) {
                // The SDK does not accept null or empty UserCredentials.
            }
        }
    }
    • USER_ID_KEY is the user's unique identification number in your application.

    • FACEBOOK_KEY is the user's Facebook ID, taken from the Facebook SDK (if your app has Facebook integration).
    • TWITTER_KEY is the user's Twitter ID, taken from the Twitter SDK (if your app has Twitter integration).
    • LINKEDIN_KEY is the user's Linkedin ID, taken from the Linkedin SDK (if your app has Linkedin integration).

    • GOOGLE_PLUS_ID is the forward compatible key that can be used to track the user's Google Plus Identifier (if your app has Google+ integration).
    • INSTALL_TOKEN_KEY is the unique install token that can identify the device (this token must be preserved across app installs).

    • MOBILE_NUMBER_KEY is the mobile phone number used for SMS messages. The mobile phone number credential is supported in SDK for Android 3.0.1 (Firebase) and above, and 2.4.6 (GCM) and above. The mobile number must include the country code, area code, and number, and omit characters such as + - . and ( ).

    If you do not have a MainApplication class in your project, you can add one by extending the Android Application class and adding its path to your manifest.

    Add a MainApplication class
    1. Create a MyApplication class that extends android.app.Application.

      package yourpackage.here;
      
      import android.app.Application;
      
      public class MyApplication extends Application {
      
          @Override
          public void onCreate() {
              super.onCreate();
          }
      
      }
      
    2. Adjust your Application Tag in your Manifest to point to your new Application class: add the name and path to the MyApplication class as shown:

      <application 
              android:name="your.package.here.MyApplication" 
              android:label="@string/app_name"  
              android:icon="@drawable/ic_launcher" 
              >
  2. For each activity in your application, add the following calls so that Kahuna can track one launch event for your application even if your application contains many activities.

    public class SampleActivity extends Activity {
    
        @Override
        protected void onStart() {
            super.onStart();
            Kahuna.getInstance().start();
            // Your Code Here
        }
    
        @Override
        protected void onStop() {
            super.onStop();
            Kahuna.getInstance().stop();
            // Your Code Here
        }
    }
  3. Add the following code to send Kahuna the credentials of users who log into your app or register for the first time.

    IKahunaUserCredentials credentials = Kahuna.getInstance().createUserCredentials();
    try {
        Kahuna.getInstance().login(credentials);
    } catch (EmptyCredentialsException e) {
        // The SDK does not accept null or empty UserCredentials.
    }
  1. Add the following code so that Kahuna knows when a user logs out of your app.

    Kahuna.getInstance().logout();

You have successfully added user credentials. Now follow the steps in Set Up Push Notifications.

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

Comments