Titanium Tianium-从Android上的文件系统获取图像文件
从文件系统获取映像时遇到问题。在iOS上运行很好 首先,我使用以下函数在文件系统中保存远程映像: img.imagen=来自远程映像的url(例如) 现在,我想分享这张图片,创建一个Android意图: args.image=f.nativePath(在上一个函数中) 我做错了什么Titanium Tianium-从Android上的文件系统获取图像文件,titanium,titanium-alloy,titanium-android,Titanium,Titanium Alloy,Titanium Android,从文件系统获取映像时遇到问题。在iOS上运行很好 首先,我使用以下函数在文件系统中保存远程映像: img.imagen=来自远程映像的url(例如) 现在,我想分享这张图片,创建一个Android意图: args.image=f.nativePath(在上一个函数中) 我做错了什么 function descargarImagen(img, callback){ var path = img.imagen; var filename = path.split("/").pop(
function descargarImagen(img, callback){
var path = img.imagen;
var filename = path.split("/").pop();
var xhr = Titanium.Network.createHTTPClient({
onload: function() {
// first, grab a "handle" to the file where you'll store the downloaded data
var f = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory, filename);
f.write(this.responseData); // write to the file
Ti.API.debug("-- Imagen guardada: " + f.nativePath);
callback({path: f.nativePath});
},
timeout: 10000
});
xhr.open('GET', path);
xhr.send();
}
var intent = null;
var intentType = null;
intent = Ti.Android.createIntent({
action: Ti.Android.ACTION_SEND
});
// add text status
if (args.status){
intent.putExtra(Ti.Android.EXTRA_TEXT, args.status);
}
// change type according to the content
if (args.image){
intent.type = "image/*";
intent.putExtraUri(Ti.Android.EXTRA_STREAM, args.image);
}else{
intent.type = "text/plain";
intent.addCategory(Ti.Android.CATEGORY_DEFAULT);
}
// launch intent
Ti.Android.currentActivity.startActivity(Ti.Android.createIntentChooser(intent, args.androidDialogTitle));