Cordova 3.x 实用插件(4) -- Android的SEND、VIEW、CALL(WebIntent)

插件地址:[url=https://github.com/Initsogar/cordova-webintent]https://github.com/Initsogar/cordova-webintent[/url]

(1)创建工程
[quote]cordova create HelloWebIntent com.rensanning.cordova HelloWebIntent
cd HelloWebIntent
cordova platform add android[/quote]

(2)安装plugin
[quote]cordova plugin add https://github.com/Initsogar/cordova-webintent.git[/quote]

(3)修改index.html后编译执行
<a href="#" class="btn" id="send">ACTION_SEND</a>
<a href="#" class="btn" id="view">ACTION_VIEW</a>
<a href="#" class="btn" id="call">ACTION_CALL</a>

<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/jquery-1.11.0.min.js"></script>
<script type="text/javascript">
$(document).on('deviceready', function() {
$('#send').on('click', send);
$('#view').on('click', view);
$('#call').on('click', call);
});

function send() {
alert("send");
var extras = {};
extras[window.plugins.webintent.EXTRA_EMAIL] = "rensanning@gmail.com";
extras[window.plugins.webintent.EXTRA_SUBJECT] = "Subject";
extras[window.plugins.webintent.EXTRA_TEXT] = "Text text";
//extras[WebIntent.EXTRA_STREAM] = "file:///android_asset/www/index.html";
window.plugins.webintent.startActivity({
action: window.plugins.webintent.ACTION_SEND,
type: 'text/plain',
extras: extras},
function() {},
function() {alert('Failed to send email via Android Intent');}
);
}

function view() {
alert("view");
window.plugins.webintent.startActivity({
action: window.plugins.webintent.ACTION_VIEW,
url: 'http://www.baidu.com'},
function() {},
function() {alert('Failed to open URL via Android Intent');}
);
}

function call() {
alert("call");
window.plugins.webintent.startActivity({
action: window.plugins.webintent.ACTION_CALL,
url: 'tel:10086'},
function() {},
function() {alert('Failed to Call TEL via Android Intent');}
);
}
</script>


[img]http://dl2.iteye.com/upload/attachment/0095/9067/fdee7a33-9cff-3c92-9cab-5851f0c53261.png[/img]

[img]http://dl2.iteye.com/upload/attachment/0095/9069/ac644c74-b897-327c-a58e-827212c3a0a7.png[/img] [img]http://dl2.iteye.com/upload/attachment/0095/9071/355828b0-d731-3ddc-a8fd-6b3aa6de59af.png[/img]

[img]http://dl2.iteye.com/upload/attachment/0095/9073/9c52101b-56d2-3f85-906a-b889bc031146.png[/img]

[img]http://dl2.iteye.com/upload/attachment/0095/9075/e4059fd3-232b-3de3-9569-a1024b706f98.png[/img]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值