HBuilder分享步骤介绍

HBuilder分享步骤介绍网址 http://jingyan.baidu.com/article/a501d80c1c55aaec630f5ec6.html?qq-pf-to=pcqq.group

例子

<head>
	<meta charset="utf-8">
	<title>分享测试</title>
	<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<link rel="stylesheet" href="css/mui.min.css">
</head>
<body>
	<header id="header" class="mui-bar mui-bar-nav">
	 <a class="mui-action-back mui-icon iconfont icon-fanhui mui-pull-left"></a>
	<h1 class="mui-title">分享测试</h1>
	</header>
	<div class="mui-content" >
		<p class="heading">链接地址:</p>
		<input id="sharehref" class="sharehref" type="url" value="http://www.baidu.com" placeholder="请输入要分享的链接地址"/>
		<p class="heading">链接标题:</p>
		<input id="sharehrefTitle" class="sharehref" type="text" value="泽富商贸" placeholder="请输入要分享的链接标题"/>
		<p class="heading">链接描述:</p>
		<input id="sharehrefDes" class="sharehref" type="text" value="泽富商贸泽富商贸" placeholder="请输入要分享的链接描述"/>
	</div>
	<footer style="position: absolute; bottom: 0px;width:100%;">
		<button class="mui-btn mui-btn-block" onclick="shareHref()">分享</button>
	</footer>
	<script src="js/mui.min.js"></script>
    <script>
		var Intent = null,
		            File = null,
		            Uri = null,
		            main = null;
		        var shares = null;
		        var shareImageUrl = '';
			        mui.plusReady(function(){
			      updateSerivces();
		            if (plus.os.name == "Android") {
		                Intent = plus.android.importClass("android.content.Intent");
		                File = plus.android.importClass("java.io.File");
		                Uri = plus.android.importClass("android.net.Uri");
		                main = plus.android.runtimeMainActivity();
		            }         
			       })
						 /**
		         * 更新分享服务
		         */
		        function updateSerivces() {
		            plus.share.getServices(function(s) {
		                shares = {};
		                for (var i in s) {
		                    var t = s[i];
		                    shares[t.id] = t;
		                }
		                outSet("获取分享服务列表成功");
		            }, function(e) {
		                outSet("获取分享服务列表失败:" + e.message);
		            });
		        }
		        /**
		         * 分享操作
		         */
		        function shareAction(id, ex) {
		            var s = null;
		            if (!id || !(s = shares[id])) {
		                outLine("无效的分享服务!");
		                return;
		            }
		            if (s.authenticated) {
		                outSet("---已授权---");
		                shareMessage(s, ex);
		            } else {
		                outSet("---未授权---");
		                s.authorize(function() {
		                    shareMessage(s, ex);
		                }, function(e) {
		                   outLine("请先安装客户端再使用分享功能");
		                });
		            }
		        }
		        /**
		         * 发送分享消息
		         */
		        function shareMessage(s, ex) {
		            var msg = {
		                href: sharehref.value,
		                title: sharehrefTitle.value,
		                content: sharehrefDes.value,
		                thumbs: ['_www/img/link.png'],
		                extra: {
		                    scene: ex
		                }
		            };
		            s.send(msg, function() {
		                outLine( "分享到\""+s.description+"\"成功! " );
		            }, function(e) {
		                outLine("分享到\""+s.description+"\"失败!");
		            });
		        }
    
    /**
     * 分享按钮点击事件
     */
    function shareHref() {
        var ids = [{
                id: "weixin", 
                ex: "WXSceneSession"  /*微信好友*/
            }, {
                id: "weixin",
                ex: "WXSceneTimeline" /*微信朋友圈*/
            }, {
                id: "qq"   /*QQ好友*/
            }],
            bts = [{
                title: "发送给微信好友"
            }, {
                title: "分享到微信朋友圈"
            }, {
                title: "分享到QQ"
            }];
        plus.nativeUI.actionSheet({
                cancel: "取消",
                buttons: bts
            },
            function(e) {
                var i = e.index;
                if (i > 0) {
                    shareAction(ids[i - 1].id, ids[i - 1].ex);
                }
            }
        );
    }       
    // 控制台输出日志
    function outSet(msg) {
        console.log(msg);
    }
    // 界面弹出吐司提示
    function outLine(msg) {
        mui.toast(msg);
    }
    </script>
</body>
  • 5
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值