Klarna Docs - Android - Getting Started

Android - Getting Started

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

    repositories {
        maven {
            url 'https://x.klarnacdn.net/mobile-sdk/'

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

    android {
        compileOptions {
            sourceCompatibility JavaVersion.VERSION_1_8
            targetCompatibility JavaVersion.VERSION_1_8

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

    dependencies {
        implementation 'com.klarna.mobile:sdk:2.x.x'

For a stable integration we require all integrators to update their SDK version at least once every quarter to ensure the application uses a recent version of the SDK. This is mainly due to continuous development on Klarna products and the SDK are being aligned by each release along with the SDK specific improvements and the nature of native mobile development where we are required to cater for platform changes as much as your application does.

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

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:

            <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>" />

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.

There are some base properties that every integration in our SDK separately defines and uses in the process. These properties are declared in an Interface called `KlarnaComponent` that each integration implements and you can set or get their values:

loggingLevelKlarnaLoggingLevelThe level of events and errors that the integration will log to the console.
eventHandlerKlarnaEventHandlerThe interface to receive results from the integration.
returnURLStringThe URL schema as defined in your AndroidManifest.xml to return from external applications.
regionKlarnaRegionThe geographical region of the user/application.
environmentKlarnaEnvironmentThe working environment of the integration.
themeKlarnaThemeThe style of integration in light and dark configurations. 
resourceEndpointKlarnaResourceEndpointThe resources endpoint configuration for the integration.

Some of the classes that implement these properties are

  • KlarnaPaymentView
  • KlarnaCheckoutView
  • KlarnaHybridSDK
  • KlarnaSignInButton

The SDK will log events and errors to the system’s log while running. You can set the logging level for the SDK using the `loggingLevel` property:

// Example of how to set the logging level for an integration
val KlarnaPaymentView = KlarnaPaymentView(...)
KlarnaPaymentView.loggingLevel = KlarnaLoggingLevel.Verbose

Possible values to set as the logging level:

KlarnaLoggingLevel.OffNo logging
KlarnaLoggingLevel.ErrorLog error messages only
KlarnaLoggingLevel.VerboseLog all messages (debug and error)

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.