当前位置:网站首页>Autojs learning - achieve file download progress
Autojs learning - achieve file download progress
2022-07-22 10:04:00 【sesame seeds】
- Click the jump =>《 Navigation post 》- Unity manual , Systematic practical learning
- Click the jump =>《 Navigation post 》- Android manual , Revisit mobile development
About author
as everyone knows , Life is a long process , constantly overcome difficulties , Constantly reflect on the process of progress . In this process, there will be a lot of questions and thoughts about life , So I decided to put my thinking , Share all your experiences and stories , To find resonance !!!
Focus on Android/Unity And various game development skills , as well as Share various resources ( Website 、 Tools 、 material 、 Source code 、 Games etc. )
If you need anything, welcome me , Communication groups make learning No longer alone .
This article is about 3 Thousand characters , Novice reading needs 8 minute , Review needs 2 minute 【 Collect at any time, no longer get lost 】
List of articles
Practice process
/** * @ function The floating window shows the progress of file download */
var app Download address =
' Your download address ';
let url = app Download address ; // update_list.url
var filePath = files.join(files.getSdcardPath(), 'myApp.apk');
log('url=' + url);
log('filePath=' + filePath);
download(url, filePath);
function download(url, filePath) {
importClass('java.io.FileOutputStream');
importClass('java.io.IOException');
importClass('java.io.InputStream');
importClass('java.net.MalformedURLException');
importClass('java.net.URL');
importClass('java.net.URLConnection');
importClass('java.util.ArrayList');
var url = new URL(url);
var conn = url.openConnection(); //URLConnection
var inStream = conn.getInputStream(); //InputStream
var fs = new FileOutputStream(filePath); //FileOutputStream
var connLength = conn.getContentLength(); //int
var buffer = util.java.array('byte', 1024); //byte[]
var byteSum = 0; // Total file size read
var byteRead; // Every time I read byte Count
log(' File size to download =');
log(connLength);
var threadId = threads.start(function() {
var w = floaty.rawWindow(
<vertical gravity="center" w="{
{device.width}}px" h="{
{device.height}}px">
<horizontal layout_gravity="center" gravity="center" bg="#ffcc00">
<text textSize="39sp"> Download progress </text>
<text textSize="39sp" id="progressNum">
0
</text>
</horizontal>
</vertical>
);
while (1) {
var File size currently written = byteSum;
var progress = ( File size currently written / connLength) * 100;
if (progress > 0.1) {
var progress = parseInt(progress).toString() + '%';
ui.run(function() {
w.progressNum.setText(progress);
});
if ( File size currently written >= connLength) {
break;
}
}
sleep(1000);
}
});
while ((byteRead = inStream.read(buffer)) != -1) {
byteSum += byteRead;
// current time
currentTime = java.lang.System.currentTimeMillis();
fs.write(buffer, 0, byteRead); // Read
}
threadId && threadId.isAlive() && threadId.interrupt();
toastLog(' Download complete ');
}
other
author : Xiaokong and Xiaozhi Xiaokong
Reprint note - Be sure to indicate the source :https://zhima.blog.csdn.net/
This Taoist friend, please Step back ️, I watch you Extraordinary bearing , There is a king's domineering spirit in his speech , There will be a great achievement in the future !!! There is give the thumbs-up Collection Today I tell you , Have you ordered it , Your success in the future ️, I don't take a penny , If it doesn't work ️, Or come back to me .
reminder : Click the card below to get more unexpected resources .
边栏推荐
猜你喜欢
智能科学创新讲堂 | 自动化所何晖光: 基于视觉信息编解码的深度学习类脑机制研究
Laravel文档阅读笔记-How to deploy Laravel 8 project on Cpanel shared hosting
Basic concept of MySQL database and deployment of MySQL version 8.0 (I)
Section 16 of Chapter 2: Circular nesting of dictionaries
Section 20 of Chapter 2: operators one
CNN的一些可视化方法
第二章 第十九节:编码和解码
跟我读论文丨Multi-Model Text Recognition Network
Let me show you eight fallacies in software design
狂神redis笔记07
随机推荐
第二章第十八节:字符集和编码
【OpenCV 例程300篇】234. 特征提取之主成分分析(PCA)
华泰证券远程开户安全吗?有保障吗?
Laravel文档阅读笔记-How to deploy Laravel 8 project on Cpanel shared hosting
微软放弃“封禁”商业开源!
黑马瑞吉外卖之后台登录与退出功能开发
Don't be ridiculous. Don't you know what abilities to improve if you want to enter a big factory? (collect quickly)
abaqus 中英文转换
&lt; 3&gt; Use of comparator
关爱世界:凯悦公布环境、社会和治理承诺及倡议的最新进展
EasyCVR平台级联时,出现报错提示端口不可达是什么原因?
First meet JS
MxCAD5.2 20190704更新
2022年简历石沉大海,别投了,软件测试岗位饱和了....
实现类LinkedList
Section 24 of Chapter 2: document operation: Writing
RHCSA 压缩也解压缩、tar归档命令、文件的上传与下载、sehll中的变量、命令别名、命令历史
第二章第二十一节:运算符.2
Moonbeam创始人解读多链新概念Connected Contract
本地数据如何高效灾备上腾讯云