Quickstart

This topic introduces how to quickly set up the Android IAPMiniProgram SDK and implement basic mini-program capabilities.

Before you begin

Before you get started, ensure you are familiar with the following things:

  • Operating systems:
    • To run HTML5 mini-programs, your device needs to be Android 4.1 (API level 16) or later.
    • To run mini programs based on DSL (Domain Specific Language), your device needs to be Android 4.2 (API level 17) or later. However, to ensure proper function, it is recommended to use devices with Android 6.0 (API level 23) or later, which requires you to set minSdkVersion in the build.gradle file to 23 or later.
  • Android Studio is installed on your computer.
  • The Gradle plugin version needs to be 4.1 or later.
  • The third-party library dependencies of the Android IAPMiniProgram SDK might conflict with the version requirements of other SDKs or your app. It is recommended to thoroughly test your app's functionalities after integration. For more information, refer to Third-party library dependencies.

Get started

To get started with IAPMiniProgram SDK, perform the following actions:

Step 1: Download the SDK

Log in to Mini Program Platform, go to the App Manage page, and click Resource > Android Resource to download IAPMiniProgram SDK for Android. A file named iapconnect_config_full is downloaded to your computer.

For more information about how to download app resources, see Download app resources.

Step 2: Add the configuration file

Add the iapconnect_config_full file in the asset directory of your Android project.

image

Step 3: Add the Maven repository

Add the Maven repository to your root build.gradle file with the following code:

copy
repositories {
    maven {
        url 'https://globaltech.alipay.com/api/v1/file/repository/minisdk/'
        credentials {
            username = USERNAME
            password = PASSWORD
        }
    }
}

In the code above, the values of username and password are desensitized. To obtain the sample codes with the values, see Credentials.

Step 4: Add dependencies

To add dependencies, follow these steps:

  1. Add the dependencies in the app-level build.gradle file with the following code:
copy
// in app build.gradle
// if there are some conflicts with existing sdk, please exclude them
dependencies {
    implementation "com.alipay.plus.android:iapminiprogram:${iapminiprogram_version}"
}
  1. Externalize the version number in the build.gradle file to easily manage upgrades with the following code:
copy
ext {
    iapminiprogram_version = 'IAPMINPROGRAM_VERSION'
}

Replace the value of IAPMINPROGRAM_VERSION with the latest version number that is provided in Android release notes.

Step 5: Initialize the SDK

After adding dependencies, you need to initialize the SDK in the application's onCreate event. Refer to the following codes for details.

Kotlin

copy
class YourApplication : Application() {
    override fun onCreate() {
        super.onCreate()
        IAPConnect.init(this, InitConfig(), object : InitCallback {
            override fun onSuccess() {
                //success
            }
            override fun onFailure(errorCode: InitErrorCode?, errorMsg: String?) {
                // failure
            }
        })
    }
}

Java

copy
public class YourApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        InitConfig initConfig = new InitConfig();
        IAPConnect.init(this, initConfig, new InitCallback() {
            @Override
            public void onSuccess() {
                // success
            }
            @Override
            public void onFailure(String errorCode, String errorMessage) {
                // failure
            }
        });  
    }
}

Step 6: Implement basic capabilities

Open a mini-program

To open a mini-program in your app, call either of the following APIs:

  • openApp: Call this API to open a mini-program with appId.
  • openUrl: Call this API to open a mini-program with a URL.

Obtain the mini-program list

To obtain the mini-program list in your app, call either of the following APIs:

  • fetchApps: Call this API to obtain the mini-program list with FetchAppRequestVO.
  • fetchAppInfoListByIds: Call this API to obtain the mini-program list with mini-program IDs.

Next steps

The steps above focus on how to integrate the Android IAPMiniProgram SDK and implement its basic capabilities. In addition to that, developers can selectively refer to the following chapters to implement advanced capabilities of the Android IAPMiniProgram SDK.

  • Integrate Native SPIs: Refer this guide to implement the following services/capabilities: obtaining user authorization, accessing user information, processing payments, scanning QR codes and barcodes.
  • Integrate SDK components: To implement capabilities related to map, multi-media, or Bluetooth, refer to this guide to integrate the corresponding pre-defined SDK components.
  • Listen for SDK events: To perform specified operations on a certain event, refer to this guide to implement specific interfaces to listen for SDK events.
  • Customize UI-related capacities: To customize certain user interfaces and related capacities, refer to this guide to implement specific interfaces.
  • Customize JSAPIs: To extend SDK functionalities via JSAPIs, refer to this guide to create new JSAPIs and override the default implementation of built-in JSAPIs.
  • Open a mini program via a promotional QR code: To allow users to open mini programs and get benefits via promotional QR codes, refer to this guide to enable opening mini programs by scanning such codes.