我使用了下面的代码,这是在http://developer.appcelerator.com/question/135462/save-screenshot-temporarily-then-retrieve-when-ready给出的公认答案
但是当电子邮件对话框打开时,它会显示一个附件,该文件是屏幕截图,但发送电子邮件后收到的电子邮件中没有附件。这意味着屏幕截图没有发送。
谁能告诉这段代码有什么问题???
var win = Ti.UI.createWindow({
// backgroundColor : '#666666'
backgroundColor : 'red',
// backgroundImage : 'img/1.jpg'
});
var btn = Ti.UI.createButton({
width : 100,
height : 30,
title : 'Test'
});
btn.addEventListener('click', function(e) {
Titanium.Media.takeScreenshot(function(e) {
var f = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory, 'test.png');
f.write(e.media);
var emailDialog = Titanium.UI.createEmailDialog();
emailDialog.setToRecipients(['test@gmail.com']);
emailDialog.setSubject('test');
emailDialog.setMessageBody('testing......');
emailDialog.setHtml(true);
emailDialog.setBarColor('black');
emailDialog.addAttachment(f.read());
emailDialog.addEventListener('complete', function(e) {
if(e.result == emailDialog.SENT) {
alert("message was sent");
}
});
emailDialog.open();
});
});
win.add(btn);
win.open();