Customize settings view

The super app can customize the appearance of the settings view of mini programs to ensure a consistent user experience. The settings view appears when a mini program invokes the my.openSetting JSAPI, allowing users to view and manage permissions that have been granted to the mini program, even if those permissions have been revoked later.

Default user interface

By default, the settings view is full-screen and displays permissions along with toggle switches for managing them. The following figure shows an example of the default UI:

image.png

Before you begin

To customize the user interface for the settings view, ensure that the integrated Android IAPMiniProgram SDK is version 2.67.0 or later. For more information, see SDK release notes.

Procedure

To customize the settings view, take the following two steps:

Step 1: Implement GriverOpenSettingViewExtension

Create a class that implements the GriverOpenSettingViewExtension interface. Within the class, override the getView method to customize the settings view. Refer to the following code for a sample implementation. For more information about the interface and its method, refer to GriverOpenSettingViewExtension.

copy
class CustomOpenSettingImpl : GriverOpenSettingViewExtension {

    override fun getView(
        param: GriverOpenSettingViewParam,
        callback: GriverOpenSettingViewCallback
    ): View {
        // Implement the logic to build a custom settings view
         val rootView = ...
        return rootView
    }
}

Step 2: Register the implementation class

After initializing the SDK, call the registerExtension API to register the implementation class (for example, CustomOpenSettingImpl in the sample) with the SDK. Refer to the following sample registration code:

copy
Griver.registerExtension(GriverExtensionManifest(
    GriverOpenSettingViewExtension::class.java,
    CustomOpenSettingImpl()
)

Interface

GriverOpenSettingViewExtension

The GriverOpenSettingViewExtension interface defines a method for the super app to customize the settings view, which the SDK then calls to render the custom view. Refer to the following code for the interface definition:

copy
interface GriverOpenSettingViewExtension : GriverExtension {

    fun getView(
        param: GriverOpenSettingViewParam,
        callback: GriverOpenSettingViewCallback
    ): View
}

The following table lists the details of the defined method:

Method

Required

Description

getView

Yes

Called by the SDK to render a custom settings view. For more information, refer to getView.

getView

The getView method has the following input parameters whose values are passed by the SDK:

Parameter

Data type

Required

Description

param

GriverOpenSettingViewParam class

Yes

An object that contains the configuration for a custom settings view.

callback

GriverOpenSettingViewCallback object

Yes

The callback that handles a permission change.

GriverOpenSettingViewParam

The GriverOpenSettingViewParam class is defined as follows:

copy
data class GriverOpenSettingViewParam(
    val activityWeakReference: WeakReference<Activity>,
    val appId: String,
    val appName: String,
    val items: List<GriverOpenSettingViewItem>
) : Serializable

The following table lists the parameter details of this class:

Parameter

Data type

Required

Description

activityWeakReference

WeakReference<Activity>

Yes

A weak reference to Activity that provides the context for UI rendering.

appId

String

Yes

The unique ID of the mini program.

appName

String

Yes

The mini program name.

items

List<GriverOpenSettingViewItem>

Yes

A list of permissions ever granted to the mini program, along with their current statuses.

GriverOpenSettingViewItem

The GriverOpenSettingViewItem class is defined as follows:

copy
data class GriverOpenSettingViewItem(
    val permissionName: String,
    val scope: String,
    val enabled: Boolean
) : Serializable

The following table lists the parameter details of this class:

Parameter

Data type

Required

Description

permissionName

String

Yes

The permission name that is displayed to users.

scope

String

Yes

The internal permission name that is defined in the code.

enabled

Boolean

Yes

Indicates whether the mini program has access to the specified permission. Valid values are:

  • true: The mini program has access.
  • false: The mini program has no access.
GriverOpenSettingViewCallback

Method

Required

Description

onChange

No

Execute this callback when the user changes a permission setting, returning the details of the updated permission. For more information, refer to onChange.

onChange

Parameter

Data type

Required

Description

changedItem

GriverOpenSettingViewItem class

Yes

The details of the updated permission.