tencent cloud

Feedback

Last updated: 2024-03-04 22:40:27

    Directions

    1. Use MiniAppProxyImpl to add a custom shared item in the capsule control panel.
    private static final String SHARE_TWITTER = "twitter";
    
    /**
    * Return a custom shared data map.
    * Operating Environment: Subprocess
    *
    * Key: Consistent with the MoreItem.id added in the getMoreItems method.
    * Value: Consistent with the MoreItem.shareKey added in the getMoreItems method.
    * @return
    */
    @Override
    public Map<String, Integer> getCustomShare(){
    Map<String, Integer> objects = new HashMap<>();
    objects.put(SHARE_TWITTER, ShareProxyImpl.OTHER_MORE_ITEM_2);
    return objects;
    }
    
    /**
    * Return the buttons for the capsule's extended panel. The ID of the extended button must be set within the range of [100, 200], otherwise, the addition will be invalid.
    * Operating Environment: Subprocess
    *
    * @param miniAppContext - The operating environment of the mini program (mini program process, not the main process)
    * @param builder
    * @return
    */
    @Override
    public ArrayList<MoreItem> getMoreItems(IMiniAppContext miniAppContext, MoreItemList.Builder builder) {
    MoreItem item2 = new MoreItem();
    item2.id = ShareProxyImpl.OTHER_MORE_ITEM_2;
    item2.text = getString(miniAppContext,
    R.string.applet_mini_proxy_impl_other2);
    item2.shareKey = SHARE_TWITTER; // The key for custom sharing, which must be set and unique, and will be used when the Mini Program end calls for control settings.
    item2.drawable = R.mipmap.mini_demo_about;
    
    builder.addMoreItem(item2)
    return builder.build();
    }
    2. To create a capsule, you can click Listener in the More Panel.
    /**
    * Return to the capsule and click Listener within the additional panel buttons.
    *
    * @return
    */
    @Override
    public OnMoreItemSelectedListener getMoreItemSelectedListener() {
    return new DemoMoreItemSelectedListener();
    }
    
    public class DemoMoreItemSelectedListener extends DefaultMoreItemSelectedListener {
    public static final int CLOSE_MINI_APP = 150;
    
    @Override
    public void onMoreItemSelected(IMiniAppContext miniAppContext, int moreItemId) {
    // Handles developers' custom click events (excluding custom sharing events)
    switch (moreItemId) {
    case CLOSE_MINI_APP:
    close(miniAppContext);
    return;
    case OTHER_MORE_ITEM_1:
    miniAppContext.getAttachedActivity().runOnUiThread(new Runnable() {
    @Override
    public void run() {
    Toast.makeText(miniAppContext.getAttachedActivity(), "custom menu click", Toast.LENGTH_SHORT).show();
    }
    });
    return;
    }
    
    // Handles built-in and developer-customized sharing, such as: Weibo, Twitter, etc.
    super.onMoreItemSelected(miniAppContext, moreItemId);
    }
    }
    3. Developers can obtain shared data in the 'share' method by receiving shares according to the specified types and clicking Event. They can then use a third-party SDK to implement the sharing functionality.
    Note:
    For how to customize buttons in the capsule menu, see Customize the Capsule.
    @ProxyService(proxy = ShareProxy.class)
    public class ShareProxyImpl extends BaseShareProxy {
    /**
    * Share
    *
    * @param shareData: Share Data
    */
    @Override
    public void share(Activity activity, ShareData shareData) {
    }
    }
    
    Contact Us

    Contact our sales team or business advisors to help your business.

    Technical Support

    Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

    7x24 Phone Support