导航:首页 > 文件教程 > android文件下载进度

android文件下载进度

发布时间:2023-06-06 07:03:48

1. 谁知道怎样在安卓手机通知栏里显示下载进度条啊

通知栏显示所用到的布局文件content_view.xml

主运行类:

packageyyy.testandroid4;

importjava.util.Timer;

importjava.util.TimerTask;

importandroid.app.Activity;

importandroid.app.AlertDialog.Builder;

importandroid.app.Notification;

importandroid.app.NotificationManager;

importandroid.app.PendingIntent;

importandroid.content.DialogInterface;

importandroid.content.Intent;

importandroid.content.pm.PackageManager.NameNotFoundException;

importandroid.os.Bundle;

importandroid.os.Handler;

importandroid.os.Message;

importandroid.view.View;

importandroid.view.View.OnClickListener;

importandroid.widget.Button;

importandroid.widget.RemoteViews;

importandroid.widget.Toast;

{

privateHandlerhandler=newHandler(){

@Override

publicvoidhandleMessage(Messagemsg){

//TODOAuto-generatedmethodstub

super.handleMessage(msg);

switch(msg.what){

case0:

notif.contentView.setTextViewText(R.id.content_view_text1,len+"%");

notif.contentView.setProgressBar(R.id.content_view_progress,100,len,false);

manager.notify(0,notif);

break;

case1:

Toast.makeText(TestAndroid4Activity.this,"下载完成",0).show();

break;

default:

break;

}

}

};

privateButtonupdate,cancel;

privateintlocalVersion,serverVersion;

privateintlen;

;

privateNotificationnotif;

/**.*/

@Override

publicvoidonCreate(BundlesavedInstanceState){

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

update=(Button)findViewById(R.id.update);

update.setOnClickListener(newOnClickListener(){

@Override

publicvoidonClick(Viewarg0){

//TODOAuto-generatedmethodstub

//点击通知栏后打开的activity

Intentintent=newIntent(TestAndroid4Activity.this,OtherActivity.class);

PendingIntentpIntent=PendingIntent.getActivity(TestAndroid4Activity.this,0,intent,0);

manager=(NotificationManager)getSystemService(NOTIFICATION_SERVICE);

notif=newNotification();

notif.icon=R.drawable.logo;

notif.tickerText="新通知";

//通知栏显示所用到的布局文件

notif.contentView=newRemoteViews(getPackageName(),R.layout.content_view);

notif.contentIntent=pIntent;

manager.notify(0,notif);

newDownLoadThread().start();

}

});

}

}

{

privateTimertimer=newTimer();

@Override

publicvoidrun(){

//TODOAuto-generatedmethodstub

super.run();

timer.schele(newTimerTask(){

@Override

publicvoidrun(){

//TODOAuto-generatedmethodstub

Messagemsg=newMessage();

msg.what=0;

msg.obj=len;

handler.sendMessage(msg);

if(len==100){

timer.cancel();

handler.sendEmptyMessage(1);

}

}

},0,1000);

len=0;

try{

while(len<100){

len++;

Thread.sleep(1000);

}

}catch(InterruptedExceptione){

//TODOAuto-generatedcatchblock

e.printStackTrace();

}

}

}

}

2. android studio 一打开项目下方就又有个下载进度条,每次打开都要下载,怎么回事啊

如果是第一次导入的项目,她会去网络仓库下载你build.gride里导入的包比如http请求的,或者第三方组件的包。会有各种类似下载的进度条。之后打开都是检查版本什么的,还有初始化项目,也会耗费一定的时间

阅读全文

与android文件下载进度相关的资料

热点内容
word2003二级标题编号 浏览:370
ipad百度云盘压缩文件 浏览:912
什么网站可以发现新产品 浏览:680
led屏用什么编程 浏览:322
创意编程怎么弄场景切换 浏览:315
解压代码选择 浏览:875
电脑开机后桌面文件全都没有了 浏览:666
wap网站论坛 浏览:55
荣耀4版本信息显示什么字母 浏览:30
dnf虫链怎么升级 浏览:956
将16进制文件读到数组中 浏览:899
caa中怎么提取框选范围数据 浏览:38
为什么用数据登不上王者 浏览:92
yaffs2根文件系统 浏览:477
剑侠情缘微信活动礼包 浏览:985
ipad版本我的世界怎么学赋魔 浏览:571
如何做好网站管理 浏览:280
汤姆猫是什么网站 浏览:913
失易得数据恢复怎么把照片 浏览:185
电脑只显示1个网络 浏览:607

友情链接