Adding the SDK as a Dependency

Add the Repository

Add the Klarna Mobile SDK repository in the apps build.gradle file.

1
2
3
4
5
    repositories {
        maven {
            url 'https://x.klarnacdn.net/mobile-sdk/'
        }
    }

Add Compile Options for the Callbacks

If you’re using Java, add compile options to support Java version 1.8 in the apps build.gradle.

1
2
3
4
5
6
7
8
    android {
        ...
        compileOptions {
            sourceCompatibility JavaVersion.VERSION_1_8
            targetCompatibility JavaVersion.VERSION_1_8
        }
        ...
    }

Add the Dependency

Add the SDK as a dependency to your app’s build.gradle.

1
2
3
    dependencies {
        implementation 'com.klarna.mobile:sdk:2.0.0'
    }

More information

For more information check out the Klarna Mobile SDK Github repository .

Configure Your App

Return URL

Both the hybrid and native integrations might, at some point, open third-party applications. To automatically return the user, these third-party applications need to know how to build a return intent or URL.

To do that, you’ll need to provide the SDK with what we call a “return URL” parameter. If you haven’t done so already, You can register an intent-filter for the Activity you’d like to return to in your app’s AndroidManifest.xml:

1
2
3
4
5
6
7
8
9
10
11
12
<application...>
    <activity...>
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
        
            <data android:scheme="<your-custom-scheme>" />
            <data android:host="<your-custom-host>" />
        </intent-filter>
    </activity>
</application>

You can read more about how deeplinks and intent filters work on the Android Developers site .

The hosting Activity should be using launchMode of type singleTask or singleTop to prevent a new instance from being created when returning from an external application.

Common Elements

Importing SDK Components

Both the Klarna Payments native integration and the hybrid integration are available under the com.klarna.mobile.sdk package.



A Common Class For Cross-cutting Concerns

Some features in the SDK are relevant for both native and hybrid integrations of the SDK. These are accessible under the CommonMobileSDKCommon class. These features are:

  • Setting a logging level.
  • Reading the device identifier.

You can read more about these below.

1. Reading the Device Indentifier

You can read the device identifier with the static function deviceIdentifier() on your KlarnaMobileSDKCommon.

This device identifier is stored in shared preferences.

Read the Identifier

1
val deviceIdentifier: String = KlarnaMobileSDKCommon.deviceIdentifier()
1
String deviceIdentifier = KlarnaMobileSDKCommon.deviceIdentifier();

2. Setting the Logging Level

The SDK will log events and errors to the system’s log while it’s running. You can read these through logcat. You can set the logging level for the SDK through the setLoggingLevel() static function on KlarnaMobileSDKCommon.

Set Level

ParamTypeDescription
Param
loggingLevel
Type
KlarnaLoggingLevel
Description
The type of events or level the SDK should log at.

KlarnaLoggingLevel values:

NameDescription
Name
Off
Description
Nothing will be logged into console.
Name
Error
Description
Only errors will be logged into console.
Name
Verbose
Description
Everything will be logged into console.
1
KlarnaMobileSDKCommon.setLoggingLevel(KlarnaLoggingLevel.Off)
1
KlarnaMobileSDKCommon.setLoggingLevel(KlarnaLoggingLevel.Off);

Internet Permissions

The SDK will require access to the internet, as such, if you don’t explicitly declare access in your manifest, we will merge manifests to get access.