[英]How to create Android Service Without interval in Appcelerator/titanium Android?
I want to create a service in appcelerator android where it starts when i click a download button and stops only if download is interrupted/fails or network is not present. 我想在appcelerator android中创建一个服务,在该服务中,当我单击下载按钮时会启动该服务,并且仅在下载中断/失败或网络不存在时才停止。
How can i achieve it? 我该如何实现? I have referred this article http://docs.appcelerator.com/platform/latest/#!/api/Titanium.Android.Service
我已经提到了这篇文章http://docs.appcelerator.com/platform/latest/#!/api/Titanium.Android.Service
I am following this http://docs.appcelerator.com/platform/latest/#!/guide/File_Uploads_and_Downloads for downloading content (videos) 我正在关注此http://docs.appcelerator.com/platform/latest/#!/guide/File_Uploads_and_Downloads下载内容(视频)
The other problem i face is ,i can't access the UI or the UI becomes almost non responsive, though i can scroll up and down. 我面临的另一个问题是,尽管我可以上下滚动,但我无法访问UI或UI几乎变得无响应。 when download is in progress on android.
在Android上进行下载时。 This is what the UI looks like and i call a function on click of download button.
这是用户界面的外观,我点击下载按钮便调用了一个函数。
NOTE: Each element,light gray rectangle is like an accordian control, which toggles(expands and retracts) on click. 注意:每个元素(浅灰色矩形)都像一个Accordian控件,单击时可进行切换(展开和缩回)。
I have written a code like this in a videoDownloader.js
file 我在
videoDownloader.js
文件中编写了这样的代码
function downloadVideos(video_download_url){
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,'video.mp4');
f.write(this.responseData); // write to the file
timeout: 10000
});
xhr.open('GET',video_download_url);
xhr.send();
}
您可能需要研究这个模块 ,它可以为您处理所有事情。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.