SuperbookKing

12.状态栏通知之notification

notification

try
{
Log.i(TAG, "service 线程文件下载:"+Thread.currentThread().getId());
showNotification(false);
Thread.sleep(10000);
} catch (InterruptedException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
showNotification(true);

//////////////////////////////

private void showNotification(boolean isFinish)
{Notification notification
;
Intent intent = new Intent(this, DemoAndroidActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent , PendingIntent.FLAG_UPDATE_CURRENT);
if (isFinish)
{
notification= new Notification(R.drawable.title, "下载完成", System.currentTimeMillis());
notification.setLatestEventInfo(this, "下载完成title", "下载完成。。。", contentIntent );
}else {
notification= new Notification(R.drawable.title, "正在下载", System.currentTimeMillis());
notification.setLatestEventInfo(this, "正在下载title", "正在下载。。。", contentIntent );
}
notification.defaults|=Notification.DEFAULT_VIBRATE;
notification.defaults|=Notification.DEFAULT_LIGHTS;
notification.defaults|=Notification.DEFAULT_SOUND;
//notification.l
NotificationManager notificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);

notificationManager.notify(R.layout.main, notification);
}

////////////取消状态栏显示///////////////

super.onStart();
Log.i(TAG, "MainActivity-->onStart");
NotificationManager notificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
notificationManager.cancel(R.layout.main);

/////////////定制的下拉通知视图//////////////////////

///////////////////////

RemoteViews contentViews = new RemoteViews(getPackageName(), R.layout.second);
notification.contentView = contentViews;
notification.contentIntent = contentIntent;
////////////////////////////

posted on 2012-07-30 18:37  SuperbookKing  阅读(162)  评论(0)    收藏  举报