android-带进度条的系统通知栏消息

/>

主运行类:

package yyy.testandroid4;

import java.util.Timer;

import java.util.TimerTask;

import android.app.Activity;

import android.app.AlertDialog.Builder;

import android.app.Notification;

import android.app.NotificationManager;

import android.app.PendingIntent;

import android.content.DialogInterface;

import android.content.Intent;

import android.content.pm.PackageManager.NameNotFoundException;

import android.os.Bundle;

import android.os.Handler;

import android.os.Message;

import android.view.View;

import android.view.View.OnClickListener;

import android.widget.Button;

import android.widget.RemoteViews;

import android.widget.Toast;

public class TestAndroid4Activity extends Activity {

private Handler handler = new Handler(){

@Override

public void handleMessage(Message msg) {

// TODO Auto-generated method stub

super.handleMessage(msg);

switch (msg.what) {

case 0:

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;

case 1:

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

break;

default:

break;

}

}

};

private Button update,cancel;

private int localVersion,serverVersion;

private int len;

private NotificationManager manager;

private Notification notif;

/** Called when the activity is first created. */

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

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

update.setOnClickListener(new OnClickListener() {

@Override

public void onClick(View arg0) {

// TODO Auto-generated method stub

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

Intent intent = new Intent(TestAndroid4Activity.this,OtherActivity.class);

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

manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

notif = new Notification();

notif.icon = R.drawable.logo;

notif.tickerText = “新通知”;

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

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

notif.contentIntent = pIntent;

manager.notify(0, notif);

new DownLoadThread().start();

}

});

}

}

private class DownLoadThread extends Thread{

private Timer timer = new Timer();

@Override

public void run() {

// TODO Auto-generated method stub

super.run();

timer.schedule(new TimerTask() {

@Override

public void run() {

// TODO Auto-generated method stub

Message msg = new Message();

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 (InterruptedException e) {

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值