2012-06-01 44 views
0

我已經建立了一個短信服務應用程序,現在我希望顯示接收短信的通知,我希望在設備(移動設備)基礎設置上使用默認方式,即如果一個選擇振動,然後振動或如果一個選擇LED然後Notification.DEFAULT_LIGHTS或如果一個選擇聲音或響,然後Notification.DEFAULT_SOUND。 是否有可能先生請幫助我在這方面或對我的壞英語抱歉或不明白。我也在下面標記我的代碼安卓通知默認振動,LED,聲音

private void displayNotification(String msg) 
{ 
    Intent i = new Intent(this.context,ZigbeeActivity.class); 
    i.putExtra("ID", ID); 
    i.putExtra("msg",msg); 
    PendingIntent pendInt = PendingIntent.getActivity(context, 0, i, 0); 
    Notification notif = new Notification(0,"Receiving SMS",System.currentTimeMillis()); 
    NotificationManager nm = (NotificationManager)context.getSystemService(context.NOTIFICATION_SERVICE); 
    notif.setLatestEventInfo(context, "SMS", msg, pendInt);  
    notif.flags = Notification.FLAG_AUTO_CANCEL; 
    notif.icon = R.drawable.notify;  
    notif.defaults |= Notification.DEFAULT_LIGHTS | Notification.DEFAULT_SOUND |  Notification.DEFAULT_VIBRATE;   
    notif.ledARGB = Color.WHITE; 
    notif.flags |= Notification.FLAG_SHOW_LIGHTS; 
    notif.ledOnMS = 1500;       
    notif.ledOffMS = 1500;  
    nm.notify(ID, notif); 
} 
+1

查看Android文檔以獲取此通知。 http://developer.android.com/guide/topics/ui/notifiers/notifications.html。澄清你的代碼中不起作用的東西。 – Orlymee

回答

4

問題出在Notification.DEFAULT_LIGHTS標誌設置。你不應該設置它。 此代碼適用於我

notification.flags |= Notification.FLAG_AUTO_CANCEL; 
    notification.defaults = Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE; 
    notification.ledARGB = Color.BLUE; 
    notification.ledOnMS = 500; 
    notification.ledOffMS = 500; 
    notification.flags |= Notification.FLAG_SHOW_LIGHTS;