tencent cloud

Feedback

Custom Sharing Capabilities

Last updated: 2024-11-21 17:31:37
The mini program SDK provides an API for sharing feature. Users can customize the sharing capability as follows:
1. Add a custom share item to the capsule control panel via MiniAppProxyImpl:
private static final String SHARE_TWITTER = "twitter";
/**
 * Returns a map of custom share data.
 * Call environment: sub-process
 *
 * key: Matches the MoreItem.id added in the getMoreItems method.
 * value: Matches the MoreItem.shareKey added in the getMoreItems method.
 * @
 */
@Override
public Map<String, Integer> getCustomShare(){
   Map<String, Integer> objects = new HashMap<>();
   objects.put(SHARE_TWITTER, ShareProxyImpl.OTHER_MORE_ITEM_2);
   return objects;
}
 
/**
 * Go back to the **More panels** button of the capsule. Set the ID of the extension button to a value in the range of [100, 200]; otherwise, it will be invalid.
 * Call environment: sub-process
 *
 * @param miniAppContext Mini program runtime environment (mini program process but not main process)
 * @param builder
 * @
 */
@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;//Custom share key, must be set and unique, used when calling control settings on the mini program side
 item2.drawable = R.mipmap.mini_demo_about;
 
 builder.addMoreItem(item2)
 return builder.build(); 
}
2. TCMPP SDK has built-in sharing buttons for QQ, Qzone, WeChat, and WeChat Circle of Friends, which can be quickly configured by overriding getDefaultShare.
/**
* Returns a list of built-in share buttons
* Calling environment: child process
*
* @return Enumeration list of built-in share buttons
*/
@Override
public List<String> getDefaultShare() {
ArrayList<String> defaultShare = new ArrayList<>();
defaultShare.add(MoreItemList.SHARE_QQ);
defaultShare.add(MoreItemList.SHARE_QZONE);
defaultShare.add(MoreItemList.SHARE_WX_FRIENDS);
defaultShare.add(MoreItemList.SHARE_WX_MOMENTS);
return defaultShare;
}
3. To create a capsule, in theMore panel, clickListeners.
/**
* Return to Capsule More Panel Button Click Listener
*
* Return
*/
Override
public OnMoreItemSelectedListener getMoreItemSelectedListener() {
return new DemoMoreItemSelectedListener(); }
}


public class DemoMoreItemSelectedListener extends DefaultMoreItemSelectedListener {
public static final int CLOSE_MINI_APP = 150; @Override


@Override
public void onMoreItemSelected(IMiniAppContext miniAppContext, int moreItemId) { //handle developer custom click event
//Handle developer-defined click events (except for custom sharing events)
switch (moreItemId) {
case CLOSE_MINI_APP: close(mini_APP)
close(miniAppContext); return
Returns;
case OTHER_MORE_ITEM_1:
miniAppContext.getAttachedActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(miniAppContext.getAttachedActivity(), "Custom menu click",Toast.LENGTH_SHORT).
}
});
Return; }
}


// Handle built-in sharing and developer custom sharing, e.g. microblogging, twitter, etc.
super.onMoreItemSelected(miniAppContext, moreItemId)}; return; }// Handle built-in sharing and developer-defined sharing, e.g. microblogging, twitter etc.
}
}
4. Receive sharing according to the following types, click the event, the developer can get the sharing data in the share method, and call the third-party SDK to implement the sharing.
@ProxyService(proxy = ShareProxy.class)
public class ShareProxyImpl extends BaseShareProxy {
/**
* Share
*
* @param shareData shareData
*/
@Override
public void share(Activity activity, ShareData shareData) {
//todo share
}
}

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