public class MainActivity extends AppCompatActivity {
String download_url="http://shouji.360tpcdn.com/160329/a9037075b8d3aa98fbf6115c54a5b895/com.alensw.PicFolder_4722404.apk";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void bt_start_service(View view){
Intent intent=new Intent(this,DownLoadService.class);
intent.putExtra("download_url",download_url);
startService(intent);
}
}
public class DownLoadService extends Service {
String download_url;
String savePath= Environment.getExternalStorageDirectory()+"/liulan.apk";
private int requestCode = (int) SystemClock.uptimeMillis();
private NotifyUtil currentNotify;
File mFile;
@Nullable
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public void onCreate() {
super.onCreate();
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
mFile=new File(savePath);
download_url=intent.getStringExtra("download_url");
Log.e("test","执行onStartCommand");
//设置想要展示的数据内容
Intent intent_noti = new Intent();
intent_noti.setAction(Intent.ACTION_VIEW);
//文件的类型,从tomcat里面找
intent_noti.setDataAndType(Uri.fromFile(mFile), "application/vnd.android.package-archive");
PendingIntent rightPendIntent = PendingIntent.getActivity(this,
requestCode, intent_noti, PendingIntent.FLAG_UPDATE_CURRENT);
int smallIcon = R.drawable.xc_smaillicon;
String ticker = "正在更新快图浏览";
//实例化工具类,并且调用接口
NotifyUtil notify7 = new NotifyUtil(this, 7);
notify7.notify_progress(rightPendIntent, smallIcon, ticker, "快图浏览升级程序", "正在下载中",
false, false, false, download_url, savePath, new NotifyUtil.DownLoadListener() {
@Override
public void OnSuccess(File file) {
mFile=file;
DownLoadService.this.stopSelf();
}
@Override
public void onFailure(Throwable t, int errorNo, String strMsg) {
}
});
currentNotify = notify7;
return super.onStartCommand(intent, flags, startId);
}
}
public void notify_progress(PendingIntent pendingIntent, int smallIcon,
String ticker, String title, String content,
boolean sound, boolean vibrate, boolean lights,
String download_url, String savePath, final DownLoadListener listener) {
setCompatBuilder(pendingIntent, smallIcon, ticker, title, content, sound, vibrate, lights);
/*
* 因为进度条要实时更新通知栏也就说要不断的发送新的提示,所以这里不建议开启通知声音。
* 这里是作为范例,给大家讲解下原理。所以发送通知后会听到多次的通知声音。
*/
FinalHttp fh = new FinalHttp();
HttpHandler<File> httpHandler=fh.download(download_url, savePath, new AjaxCallBack<File>() {
@Override
public void onLoading(long count, long current) {
super.onLoading(count, current);
double a=count;
double b=current;
double currentPro=(double)((b/a)*100);
cBuilder.setProgress(100, (int)currentPro, false);
sent();
}
@Override
public void onSuccess(File file) {
super.onSuccess(file);
cBuilder.setContentText("下载完成").setProgress(0, 0, false);
sent();
listener.OnSuccess(file);
}
@Override
public void onFailure(Throwable t, int errorNo, String strMsg) {
super.onFailure(t, errorNo, strMsg);
listener.onFailure(t,errorNo,strMsg);
}
});
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有