我正在为我的客户创建一个应用程序,他的一个要求是在设备上下载并安装外部apk(大小约为62mb)。设备将被植根,所以这不是问题。但是,在使用user_data_ins = ('''
#!/usr/bin/python
import os
import subprocess
import time
import uuid
def shell_command_execute(command):
p = subprocess.Popen(command, stdout=subprocess.PIPE, shell=True)
(output, err) = p.communicate()
print output
return output
repo = "{0}"
playbook = "{1}"
echo_bash_profile = "echo {2} >> ~/.bash_profile" % user_echo
shell_command_execute(echo_bash_profile)
var_user_data = "{3}"
for varb in var_user_data.split('|'):
echo_bash_profile_passed = "echo " + varb + " >> ~/.bash_profile"
shell_command_execute(echo_bash_profile_passed)
command = 'git clone ' + repo
shell_command_execute(command)
folder = repo.split('/')[4].replace('.git','')
#https://github.com/zukeru/vision_provis.git
execute_playbook = ('ansible-playbook -i "localhost," -c local' + '/' + os.path.dirname(os.path.realpath(__file__)) + '/' + folder + '/' + playbook >> ansible.log')
print execute_playbook
shell_command_execute(execute_playbook)
'''.format(str(repo), str(playbook),str(user_data_ins), str(in_user_data)))
下载apk时,AsyncTask
在达到34%(每次精确34%,甚至在不同的设备上)后重置为0%并抛出progress bar
。
以下是我正在使用的代码:
java.io.IOException: unexpected end of stream
答案 0 :(得分:1)
I tried everything to make this code work. But, it didn't. Then I found an alternative to this. I tried (completing-read "Tag: " (mapcar #'first org-tag-persistent-alist) nil t)
to download the apk, and surprisingly it worked. I think IntentService
might have some kind of limit for downloading. To download using AsyncTask
I used this code. The answer is very informative. It also has some other alternatives for downloading.
答案 1 :(得分:0)
您应该为 HttpURLConnection 添加连接超时。
HttpURLConnection c = (HttpURLConnection) url.openConnection();
c.setRequestMethod("GET");
c.setDoOutput(true);
//set timeout to 5 seconds , set your time here
c.setConnectTimeout(5000);
c.connect();
它对我有用。我希望它为你工作。