# Mini-Program Permissions

This document primarily introduces methods, delegate classes, and other components related to Mini-Program Scope permissions.

# 1. Pre-processing Permission Requests

Supported App Types

Mini-Program ✅ Mini-Game ✅ H5 Application 🚫

Starting from version 2.40.3, the Host-App can perform pre-processing on permission requests within Mini-Programs.

The host project should implement the IAuthRequestHandler interface. Refer to: 「IAuthRequestHandler」

# 2. Handling Permission Request Results

Supported App Types

Mini-Program ✅ Mini-Game ✅ H5 Application 🚫

Starting from version 2.40.3, the Host-App can receive the results of permission requests within Mini-Programs. (Currently supports APIs related to the Core SDK and Extension SDK only).

The host project should implement the IAuthResultHandler interface. Refer to: 「IAuthResultHandler」

# 3. Customizing the Title and Text in the Privacy Authorization Dialog Details

Supported App Types

Mini-Program ✅ Mini-Game ✅ H5 Application 🚫

Starting from version 2.40.3, the Host-App can customize the title and text in the details section of the privacy authorization dialog.

The host project should implement the IAuthInfoHandler interface. Refer to: 「IAuthInfoHandler」

# 4. Customizing the Mini-Program Permission Settings Page

Starting from version 2.40.3, the Host-App can customize the Mini-Program permission settings page.

# 4.1 Implementation

Supported App Types

Mini-Program ✅ Mini-Game ✅ H5 Application 🚫

The host project should implement the IScopeSettingHandler interface. Refer to: 「IScopeSettingHandler」

# 4.2 Obtaining the Current List of Mini-Program Permissions for a Mini-Program

Supported App Types

Mini-Program ✅ Mini-Game ✅ H5 Application 🚫

Use the getScopeList method of FinAppClient or FinAppProcessClient, depending on the process context during execution.

Example:

if (FinAppClient.isFinAppProcess(context)) {
    // Mini-Program process
    val scopeList = FinAppProcessClient.getScopeList(context, appId)
} else {
    // Main process
    val scopeList = FinAppClient.getScopeList(context, appId)
}

The ScopeBean objects within the result set have the following methods:

Get the scope value:

scope.scope

Get the title corresponding to the scope:

scope.getScopeName(context)

Get the description corresponding to the scope:

 scope.getDesc(context)

Get the status of the scope:

scope.isAllow()
// or
scope.isDisallow()
// or
scope.isAllowWhenUsing() // Primarily used for the "Allow when using the Mini-Program" option for location permissions.

# 4.3 Modifying the Mini-Program Permission Status for a Mini-Program

Supported App Types

Mini-Program ✅ Mini-Game ✅ H5 Application 🚫

Use the updateScopeStatus method of FinAppClient or FinAppProcessClient, depending on the process context during execution.

Example:

if (FinAppClient.isFinAppProcess(context)) {
    // Mini-Program process
    FinAppProcessClient.updateScopeStatus(
        context,
        appId,
        scope,
        AppletScopeBean.Status.ALLOW
    )
} else {
    // Main process
    FinAppClient.updateScopeStatus(
        context,
        appId,
        scope,
        AppletScopeBean.Status.ALLOW
    )
}

Supported statuses:

Status Value Description
UNSET Not Set
DISALLOW Deny
ALLOW_WHEN_USING Allow when using the Mini-Program, primarily for location permissions
ALLOW Allow

# 5. Customizing Part of the Scope Permission Request Dialog Content

Supported App Types

Mini-Program ✅ Mini-Game ✅ H5 Application 🚫

Starting from version 2.40.11, partial content of the Scope permission request dialog can be customized.

The host project should implement the ScopeDialogCustomHandler interface. Refer to: 「ScopeDialogCustomHandler」

# 6. Opening the Mini-Program Authorization Management Page

This method opens a page displaying a list of all previously used Mini-Programs and their associated permissions.

# 6.1 Standard Opening

Example:

FinAppClient.appletApiManager.openPrivacyManage(context)

# 6.2 Opening with Custom Navigation Bar

Example:

val config = AppletScopeManagerConfig()
config.backImageRes = R.drawable.back
config.isCenterTitle = false
FinAppClient.appletApiManager.openPrivacyManage(context, config)

Configuration Item Description:

Variable Name Description
backImageRes The image resource file for the back button. To support Dark Mode, prepare corresponding dark mode image resources and place them in the appropriate 'night' directory.
isCenterTitle Whether to center the title. true for centered, false for left-aligned, null to follow the global configuration set during SDK initialization.

Supported App Types

Mini-Program ✅ Mini-Game ✅ H5 Application 🚫

This method allows the Host-App to obtain privacy authorization related configuration information for a Mini-Program.

Example:

if (FinAppClient.isFinAppProcess(context)) {
    // Mini-Program process
    FinAppProcessClient.appletProcessApiManager.getPrivacyInfo(
        context,
        object : FinSimpleCallback<PrivacyInfo>() {
            override fun onSuccess(result: PrivacyInfo) {
                // Callback for successfully obtaining privacy authorization information
            }
  
            override fun onError(code: Int, error: String?) {
                // Callback for failing to obtain privacy authorization related information
            }
        })
} else {
    // Main process
    FinAppClient.appletApiManager.getPrivacyInfo(
        this,
        apiServer,
        appId,
        object : FinSimpleCallback<PrivacyInfo>() {
            override fun onSuccess(result: PrivacyInfo) {
                // Callback for successfully obtaining privacy authorization information
            }

            override fun onError(code: Int, error: String?) {
                // Callback for failing to obtain privacy authorization related information
            }
        })
}

PrivacyInfo Related Description:

Variable Name Description
defaultPrivacyName The name of the default privacy agreement
defaultPrivacyContent The content of the default privacy agreement, in HTML code
customPrivacyName The name of the custom privacy agreement
customPrivacyUrl The URL of the custom privacy agreement

# 8. Custom Mini-Program (Scope) Permissions

Supported App Types

Mini-Program ✅ Mini-Game ✅ H5 Application 🚫

Custom Scope permissions are typically implemented in conjunction with custom APIs.

A custom API class should inherit the abstract class ScopeApi and, like other regular custom APIs, implement the corresponding abstract methods:

public class CustomScopeApi extends ScopeApi {

    public CustomScopeApi(@NonNull Context context) {
        super(context);
    }

    @Override
    public String[] apis() {
        // Define the custom API methods handled by this class here
        return new String[]{"customScopeApi"};
    }

    @Override
    public void invoke(String event, JSONObject param, ICallback callback) {
        if (event.equals("customScopeApi")) {
            customScopeApi(callback);
        }
    }
}

Create custom permissions, create a custom View, and display the dialog:

private void customScopeApi(ICallback callback) {
    View view = createCustomView(callback);
    // Display the dialog
    checkScope(view);
}

private View createCustomView(ICallback callback) {
    // Custom ID card permission
    AppletScopeBean idCardScopeBean = new AppletScopeBean(
            "scope.idCard",
            "ID Card",
            "Get ID Card Information",
            "Obtain your ID card information for XXXXXX"
    );
    // Custom phone number permission. Note: 'scope.getPhoneNumber' conflicts with the built-in Scope permission and will be ignored; shown for example only.
    AppletScopeBean phoneNumScopeBean = new AppletScopeBean(
            "scope.getPhoneNumber",
            "Phone Number",
            "Get Phone Number Information",
            "Obtain your phone number information for XXXXXX"
    );
    // Custom digital wallet permission
    AppletScopeBean walletScopeBean = new AppletScopeBean(
            "scope.wallet",
            "Digital Wallet",
            "Get Digital Wallet Information",
            "Obtain your digital wallet information for XXXXXX"
    );
    // Create a custom View and handle interaction events
    View view = LayoutInflater.from(getContext()).inflate(R.layout.layout_custom_scope, null);
    view.findViewById(R.id.btnConfirm).setOnClickListener(v -> {
        // Set ID card permission status
        AppletScopeBean.Status idCardStatus = view.findViewById(R.id.cbIdCard).isChecked()
                ? AppletScopeBean.Status.ALLOW
                : AppletScopeBean.Status.DISALLOW;
        idCardScopeBean.setStatus(idCardStatus);
        // Set phone number permission status
        AppletScopeBean.Status phoneNumStatus = view.findViewById(R.id.cbPhoneNum).isChecked()
                ? AppletScopeBean.Status.ALLOW
                : AppletScopeBean.Status.DISALLOW;
        phoneNumScopeBean.setStatus(phoneNumStatus);
        // Set digital wallet permission status
        AppletScopeBean.Status walletStatus = view.findViewById(R.id.cbWallet).isChecked()
                ? AppletScopeBean.Status.ALLOW
                : AppletScopeBean.Status.DISALLOW;
        walletScopeBean.setStatus(walletStatus);
        // Close the dialog and update the permission statuses
        dismiss(Arrays.asList(idCardScopeBean, phoneNumScopeBean, walletScopeBean));
        // Execute your other business logic after the permission request, such as callback results, etc.
        callback.onSuccess(new JSONObject());
    });
    return view;
}

The checkScope method in the code example above is used to trigger the Scope permission request dialog. The view parameter passed in is the custom layout.

Developers need to handle the interactions within the custom view and call the dismiss method when the request is complete, passing in the list of custom Scope permission objects with their 【set statuses】, and then close the dialog.

The following is the layout file code for R.layout.layout_custom_scope, provided for reference alongside the example above:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <CheckBox
        android:id="@+id/cbIdCard"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="ID Card" />

    <CheckBox
        android:id="@+id/cbPhoneNum"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Phone Number (conflicts with built-in permission, will be ignored)" />

    <CheckBox
        android:id="@+id/cbWallet"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Digital Wallet" />

    <Button
        android:id="@+id/btnConfirm"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:layout_marginBottom="16dp"
        android:background="@android:color/holo_green_light"
        android:text="Confirm" />

</LinearLayout>

Note

  • The list of built-in Scope permissions mentioned above is as follows:

    • scope.userInfo
    • scope.userLocation
    • scope.userLocationBackground
    • scope.record
    • scope.writePhotosAlbum
    • scope.camera
    • scope.bluetooth
    • scope.addPhoneContact
    • scope.getPhoneNumber
    • scope.addPhoneCalendar
  • When registering the API implementation class (i.e., customScopeApi in the example above), register it in the corresponding process.

    That is, if using single-process mode, register the API in the main process;

    If using multi-process mode, register the API in the child process;

    If both single-process and multi-process modes might be used, register the API in both the main process and the Mini-Program process.

# 9. Listening for Changes in Mini-Program Status within the Default Settings Page

Supported App Types

Mini-Program ✅ Mini-Game ✅ H5 Application 🚫

Starting from version 2.41.7, listening for changes in Mini-Program permissions resulting from user actions within the settings page is supported.

The host project should implement the IScopeStatusChangeHandler interface. Refer to: 「IScopeStatusChangeHandler」

© FinClip with ❤ , Since 2017