安卓原生开发我们可以使用友盟的ShareSDK或者调用系统的分享,那么在weex开发时,如何实现呢
这里我们就不得不提一下weex的安卓扩展,这里我们调用手机系统的分享。
@WXModuleAnno(runOnUIThread = true)
public void share(String msg){
if(mWXSDKInstance.getContext() instanceof Activity) {
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_TEXT, msg);
shareIntent.setType("text/plain");
shareIntent.putExtra(Intent.EXTRA_SUBJECT,"好友分享");
shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mWXSDKInstance.getContext().startActivity(Intent.createChooser(shareIntent,"分享到"));
}
}
写一个module的扩展,然后再js里面调用
share:function(){
var self = this;
var content = self.jokecontent;
require('@weex-module/myModule').share(content);
}
最终效果就是:
项目地址------》点击打开链接