Mini program requests system permissions
When using mini programs, some APIs require not only mini program authorization but also corresponding Android system permissions to function correctly. By default, the SDK will automatically prompt the user to grant these system permissions when needed. However, you can disable this automatic permission request during SDK initialization. In this case, the host app must handle these system permission requests to ensure the mini program APIs work properly.
@ProxyService(proxy = MiniConfigProxy.class)
public class MiniConfigProxyImpl extends MiniConfigProxy {
@Override
public Application getApp() {
return "app Application";
}
@Override
public MiniInitConfig buildConfig() {
MiniInitConfig.Builder builder = new MiniInitConfig.Builder();
MiniInitConfig config = builder
.configAssetName("tcmpp-android-configurations.json")
.imei("IMEI")
.autoRequestPermission(false)
.debug(true)
.build();
}
}
Customize system permission requests
By implementing the IPermissionManagerProxy API, you can intercept and customize the logic for mini program system permission requests. The IPermissionManagerProxy API includes three methods: isPermissionGranted to check if the host has a specific system permission, and requestForPermission and requestForPermissions to notify the host to request one or multiple permissions.
Note:
Once you customize system permission requests, the autoRequestPermission setting in the initialization configuration will no longer be effective.
@ProxyService(proxy = IPermissionManagerProxy.class)
public class PermissionProxyImpl implements IPermissionManagerProxy {
@Override
public boolean isPermissionGranted(Context context, String permission) {
return ContextCompat.checkSelfPermission(context, permission) == PackageManager.PERMISSION_GRANTED;
}
@Override
public void requestForPermission(Activity activity, String permission, RequestPermissionCallback callbacks) {
Toast.makeText(activity,"applying for" + permission + "permission", Toast.LENGTH_LONG).show();
}
@Override
public void requestForPermissions(Activity activity, String[] permissions, RequestPermissionCallback callbacks) {
Toast.makeText(activity,"applying for" + permissions[0] + "permissions," Toast.LENGTH_LONG).show();;
}
}
interface RequestPermissionCallback {
void onSuccess();
void onFail(String[] rejected);
}
Was this page helpful?