你好,游客 登录 注册 搜索
背景:
阅读新闻

Android自定义Notification

[日期:2011-10-30] 来源:Linux社区  作者:furongkang [字体:大 中 小]

创建Notification:

  1. public class CustomNotificationActivity extends Activity {  
  2.     NotificationManager notificationManager;  
  3.     @Override  
  4.     public void onCreate(Bundle savedInstanceState) {  
  5.         super.onCreate(savedInstanceState);  
  6.         setContentView(R.layout.main);  
  7.         //获取到系统的notificationManager   
  8.         notificationManager =  (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);  
  9.     }  
  10.       
  11.     public void click(View view ){  
  12.         //实例化一个notification    
  13.          String tickerText = "IP号码 设置完毕";  
  14.          long when = System.currentTimeMillis();  
  15.          Notification notification = new Notification(R.drawable.icon, tickerText, when);  
  16.            
  17.          //不能手动清理   
  18.          //notification.flags= Notification.FLAG_NO_CLEAR;   
  19.          //添加音乐   
  20.          //notification.sound = Uri.parse("/sdcard/haha.mp3");    
  21.            
  22.          //设置用户点击notification的动作    
  23.          // pendingIntent 延期的意图    
  24.          Intent intent = new Intent(this,Bactivity.class);  
  25.          PendingIntent pendingIntent  = PendingIntent.getActivity(this, 0, intent, 0);  
  26.          notification.contentIntent = pendingIntent;  
  27.           
  28.          //自定义界面    
  29.          RemoteViews rv = new RemoteViews(getPackageName(), R.layout.noti_layout);  
  30.          rv.setTextViewText(R.id.tv_rv, "我是自定义的 notification");  
  31.          rv.setProgressBar(R.id.pb_rv, 80, 20, false);  
  32.          notification.contentView = rv;  
  33.            
  34.          //把定义的notification 传递给 notificationmanager    
  35.          notificationManager.notify(0, notification);  
  36.     }  
  37. }  
linux
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款