Customize the share capacity
Customize the user authorization view
When the Merchants' mini program calls some APIs, such as contact, photo album, geographical location, and other related APIs, it is important to obtain consent from users to protect their privacy. Users have the right to refuse the mini program to call these sensitive APIs. The user authorization view is shown below.
Griver has implemented the default authorization view. The authorization view can be customized by GriverLocalAuthDialogExtension
.
GriverLocalAuthDialogExtension
public interface GriverLocalAuthDialogExtension extends GriverExtension {
/**
* Create authorization dialog, the dialog ususally has two buttons for 'Allow' and 'Don't allow'.
* @param context the current context.
* @return the authorization dialog.
*/
LocalPermissionDialog createLocalPermissionDialog(Context context);
}
LocalPermissionDialog
public interface LocalPermissionDialog {
/**
* Accord the scopes to set the content of authorization dialog.
* @param scopes The scopes of the device permissions that need to be granted
* @param content Show the content in the authorization dialog
* @param title Show the title in the authorization dialog
* @param icon Show the icon in the authorization dialog
*/
void setDialogContent(List<String> scopes, String content, String title, String icon);
/**
* Set the listener of agree to authorization or cancel authorization.
* @param listener The listener of agree to authorization or cancel authorization.
*/
void setPermissionPermitListener(PermissionPermitListener listener);
/**
* Show authorization dialog.
* @param page the current page.
*/
void show(Page page);
}
The LocalPermissionDialog.setDialogContent
can set the title, icon, and content in the authorization dialog, and the relationship can refer to the picture below.
The relationship between scope and JSAPI
Scope | JSAPI |
scope.location | my.getLocation my.chooseLocation my.openLocation |
scope.album | my.chooseImage my.saveImage |
scope.camera | my.scan my.chooseImage |
Sample code
GriverLocalAuthDialogExtensionImpl
Implement the GriverLocalAuthDialogExtension
.
public class GriverLocalAuthDialogExtensionImpl implements GriverLocalAuthDialogExtension {
@Override
public LocalPermissionDialog createDialog(Context context) {
return new NebulaLocalPermissionNoticeDialog(context);
}
}
NebulaLocalPermissionNoticeDialog
Implement the LocalPermissionDialog
.
public class NebulaLocalPermissionNoticeDialog implements LocalPermissionDialog {
Context context;
private String title;
private String message;
private PermissionPermitListener permissionPermitListener;
public NebulaLocalPermissionNoticeDialog(Context context) {
this.context = context;
}
@Override
public void setDialogContent(List<String> scopes, String s, String s1, String s2) {
title = s1;
message = s;
}
@Override
public void setPermissionPermitListener(
final PermissionPermitListener permissionPermitListener) {
this.permissionPermitListener = permissionPermitListener;
}
@Override
public void show(Page page) {
CreateDialogParam createDialogParam = new CreateDialogParam(title, message,
context.getString(R.string.griver_core_allow),
context.getString(R.string.griver_core_deny), null);
createDialogParam.cancelable = false;
createDialogParam.positiveListener = new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
permissionPermitListener.onSuccess();
}
};
createDialogParam.negativeListener = new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
permissionPermitListener.onFailed(-1,
context.getString(R.string.griver_core_user_unauthorized), true);
}
};
RVProxy.get(GriverDialogExtension.class).createDialog(GriverEnv.getTopActivity().get(),
createDialogParam).show();
}
Register the extension after Griver is initialized
Griver.registerExtension(new GriverExtensionManifest(
GriverLocalAuthDialogExtension.class, new GriverLocalAuthDialogExtensionImpl()));