2011-06-08 60 views

回答

0
   String ns = Context.NOTIFICATION_SERVICE; 
       NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns); 
       int icon = R.drawable.icon;  
       CharSequence tickerText = "Notification Receive"; 
       long when = System.currentTimeMillis(); 

       Notification notification = new Notification(icon, tickerText, when); 

       Context context1 = context; 
       //***************** 
       final int CUSTOM_VIEW_ID = 1; 
       RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.custom_notification_layout); 
       contentView.setImageViewResource(R.id.image, R.drawable.icon); 
       contentView.setTextViewText(R.id.text, "Racquetime \n"+msg); 

       notification.contentView = contentView; 


       notification.defaults=Notification.FLAG_ONLY_ALERT_ONCE+Notification.FLAG_AUTO_CANCEL; 
       Intent notificationIntent; 
       if(GUIStatics.boolLoginStatus) 
       { 
        notificationIntent = new Intent(this,ShowAllNotificationActiviry.class); 
       } 
       else{ 
        notificationIntent = new Intent(this, HomeActivity.class); 
       } 
       notification.flags |= Notification.FLAG_AUTO_CANCEL; 
       notification.defaults |= Notification.DEFAULT_SOUND; 
       notification.flags |= Notification.FLAG_SHOW_LIGHTS; 

       notificationIntent.putExtra("Tag", "C2DMBaseReceiver"); 
       PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); 
       notification.contentIntent = contentIntent; 
       mNotificationManager.notify(CUSTOM_VIEW_ID, notification); 

我使用這個代碼用於顯示通知欄,您可以更改通知它根據您的要求。 我希望這是幫助。