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";
@Override
public Map<String, Integer> getCustomShare(){
Map<String, Integer> objects = new HashMap<>();
objects.put(SHARE_TWITTER, ShareProxyImpl.OTHER_MORE_ITEM_2);
return objects;
}
@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;
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.
@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.
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) {
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; }
}
super.onMoreItemSelected(miniAppContext, moreItemId)}; return; }
}
}
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 {
@Override
public void share(Activity activity, ShareData shareData) {
}
}
Was this page helpful?