onCapsuleButtonCloseClick 方法返回值表示是否自定义关闭按钮监听,返回值为 true 表示自定义,false(默认值)表示使用默认监听。/*** 点击胶囊按钮的关闭选项* 调用环境:子进程** @param miniAppContext 小程序运行环境(小程序进程,非主进程)* @param onCloseClickedListener 点击小程序关闭时回调* @return 不支持该接口,请返回false*/public abstract boolean onCapsuleButtonCloseClick(IMiniAppContext miniAppContext,DialogInterface.OnClickListener onCloseClickedListener);
@Overridepublic boolean onCapsuleButtonCloseClick(IMiniAppContext miniAppContext,DialogInterface.OnClickListener onCloseClickedListener) {Log.e("TAG","onCapsuleButtonCloseClick"+miniAppContext.getMiniAppInfo());//handle close mini app eventreturn true;}
/*** 点击胶囊按钮的更多选项** @param miniAppContext 小程序运行环境* @return 不支持该接口,请返回false*/public abstract boolean onCapsuleButtonMoreClick(IMiniAppContext miniAppContext);
@Overridepublic boolean onCapsuleButtonMoreClick(IMiniAppContext miniAppContext) {// 弹出自定义更多面板return true;}
/*** 返回胶囊更多面板的按钮,扩展按钮的ID需要设置为[100, 200]这个区间中的值,否则,添加无效* 调用环境:子进程** @param builder* @return*/public abstract ArrayList<MoreItem> getMoreItems(MoreItemList.Builder builder);
@Overridepublic ArrayList<MoreItem> getMoreItems(IMiniAppContext miniAppContext, MoreItemList.Builder builder) {MoreItem item1 = new MoreItem();// 设置菜单id(必须),扩展按钮的ID需要设置为[100, 200]这个区间中的值,否则,添加无效。item1.id = ShareProxyImpl.OTHER_MORE_ITEM_1;// 设置菜单标题(可选)item1.text = getString(miniAppContext, R.string.applet_mini_proxy_impl_other1);// 设置菜单图标(可选)item1.drawable = R.mipmap.mini_demo_about;// 设置无障碍描述(可选), 默认是菜单标题item2.contentDescription = "菜单无障碍描述";// 监听点击事件item2.onClickListener = new MoreItem.MoreItemClickListener() {@Overridepublic void onClick(IMiniAppContext context, MoreItem item) {// 处理点击事件}};// 自行调整顺序。builder.addMoreItem(item1)// 根据需求添加内置菜单项.addRestart(getString(miniAppContext, R.string.applet_mini_proxy_impl_restart),R.mipmap.mini_demo_restart_miniapp)// 根据需求添加内置菜单项.addAbout(getString(miniAppContext, R.string.applet_mini_proxy_impl_about),R.mipmap.mini_demo_about)// 根据需求添加内置菜单项.addSetting(getString(miniAppContext, R.string.mini_sdk_more_item_setting_0),R.drawable.mini_sdk_setting,//设置无障碍描述(可选), 默认是菜单标题"小程序设置");return builder.build();}private String getString(IMiniAppContext miniAppContext, int id) {return miniAppContext.getContext().getString(id);}
@Overridepublic OnMoreItemSelectedListener getMoreItemSelectedListener() {return new CustomMoreItemSelectedListener();}
public class CustomMoreItemSelectedListener implements OnMoreItemSelectedListener {private static final String TAG = "CustomMoreItemSelectedListener";// "关于"选项的 itemType 值private static final int ITEM_ABOUT = 5;@Overridepublic void onMoreItemSelected(IMiniAppContext context, int itemType) {Log.d(TAG, "onMoreItemSelected called with itemType: " + itemType);// 获取 Android ContextContext androidContext = context.getContext();switch (itemType) {case ITEM_ABOUT:Log.d(TAG, "Handling ABOUT item");openAboutPage(androidContext);break;default:// 其他菜单项打印日志便于调试,也可以根据需求自行处理Log.d(TAG, "Unhandled menu item type: " + itemType);Toast.makeText(androidContext, "菜单项类型: " + itemType, Toast.LENGTH_SHORT).show();break;}}private void openAboutPage(Context context) {try {// 使用 Application Context 启动 Activity// 需要添加 FLAG_ACTIVITY_NEW_TASKIntent intent = new Intent(context, AboutActivity.class);intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);intent.putExtra("app_name", "TCMPP Demo");intent.putExtra("app_description", "A demo application for TCMPP Mini SDK");intent.putExtra("app_version", "1.0.0");intent.putExtra("avatar_url", "");intent.putExtra("service_statement", "Service Statement");intent.putExtra("service_url", "https://example.com/service-statement");context.startActivity(intent);Log.d(TAG, "Started AboutActivity successfully");} catch (Exception e) {Log.e(TAG, "Error launching AboutActivity: " + e.getMessage(), e);}}}
文档反馈