var Context = null,
File = null,
Uri = null,
main = null;
mui.plusReady(function() {
if(plus.os.name == "Android") {
//导入Java类对象
Context = plus.android.importClass("android.content.Intent");
File = plus.android.importClass("java.io.File");
Uri = plus.android.importClass("android.net.Uri");
//获取应用主Activity
main = plus.android.runtimeMainActivity();
}
});
function share(shareTip, shareFile) {
//将类Context的这个行为(Action)ACTION_SEND,赋给shareIntent
var shareIntent = new Context(Context.ACTION_SEND);
//***以下两种写法是一样的
//plus.android.invoke(shareIntent,"setType","text/plain");
//plus.android.invoke(shareIntent,"putExtra",Context.EXTRA_TEXT,shareText);
//设置分享类型
shareIntent.setType("application/pdf");
//设置分享的内容
shareIntent.putExtra(Context.EXTRA_STREAM, Uri.fromFile(shareFile));
//***以上两种写法是一样的
//指定分享的包名
//shareIntent.setPackage('com.tencent.mm',);
main.startActivity(Context.createChooser(shareIntent, shareTip));
}
function createDownload(url) {
var date = getNowFormatDate();
if(date == localStorage.getItem("lastdate")) {} else {
localStorage.setItem("lastdate", getNowFormatDate());
clearDownload();
}
var dtask = plus.downloader.createDownload(url)
}, function(d, status) {
// 下载完成
if(status == 200) {
mui.toast("下载完成!");
try {
var file = new File(plus.io.convertLocalFileSystemURL(d.filename));
} catch(e) {
alert(e);
}
share("hello", file);
} else {
alert("Download failed: " + status);
}
});
//dtask.addEventListener( "statechanged", onStateChanged, false );
dtask.start();
}
0 个回复