0

我现在已经构建了一个短信服务应用程序我希望在接收短信时显示通知,我希望在基于设备(移动设备)的设置上使用默认方式,即如果一个选择振动然后振动,或者如果一个选择 LED 然后Notification.DEFAULT_LIGHTS或者如果一个选择声音或然后响铃Notification.DEFAULT_SOUND。先生是否可以在这方面帮助我,或者对我的英语不好或不明白感到抱歉。我还在下面标记了我的代码

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);
}
4

1 回答 1

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;
于 2013-08-02T18:57:06.933 回答