package net.codepig.servicedownloaderdemo;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends AppCompatActivity {
private String _url="http://www.boosj.com/apk/boosjDance.apk";
private EditText urlText;
private Button goBtn;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
goBtn=(Button) findViewById(R.id.goBtn);
urlText=(EditText) findViewById(R.id.urlText);
urlText.setText(_url);
goBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
_url=urlText.getText().toString();
//start download
start_service();
}
});
}
public void start_service(){
//等会再填
}
}
package net.codepig.servicedownloaderdemo;
import android.app.IntentService;
import android.content.Intent;
/**
* 下载服务
* Created by QZD on 2017/9/20.
*/
public class DownLoadService extends IntentService {
public DownLoadService() {
super("DownLoadService");//这就是个name
}
@Override
public void onCreate() {
super.onCreate();
}
protected void onHandleIntent(Intent intent) {
Bundle bundle = intent.getExtras();
String downloadUrl = bundle.getString("download_url");
Log.d(TAG,"下载启动:"+downloadUrl);
Thread.sleep(1_000);
int count=0;
while(count<20){
count++;
Log.d(TAG,"下载运行中--"+count);
Thread.sleep(1000);
}
Log.d(TAG,"下载结束");
}
@Override
public void onDestroy() {
Log.d(TAG, "onDestroy");
super.onDestroy();
}
}
public void start_service(){
Intent intent=new Intent(this,DownLoadService.class);
intent.putExtra("download_url",_url);
startService(intent);
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有