w***@qq.com
w***@qq.com
  • 发布:2018-09-18 16:51
  • 更新:2018-09-18 16:51
  • 阅读:2150

File is not a constructor,为什么本地打包之后就报这个错,直接用hbulider真机调试时没问题的

分类:Native.js

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();
}

2018-09-18 16:51 负责人:无 分享
已邀请:

该问题目前已经被锁定, 无法添加新回复