简体   繁体   中英

Android Notification default for Vibrate,Led,Sound

I have build a sms Service Application now I wish to display notification on Receiving SMS in which I wish to use dafault means on device(Mobile Device) based setting ie if one select Vibration then Vibrate or if one select LED then Notification.DEFAULT_LIGHTS or if one select Sound or ring then Notification.DEFAULT_SOUND . Is it possible sir please help me in this regards or sorry for my bad English or not understand. I also tag my code below

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

The problem is in Notification.DEFAULT_LIGHTS flag set. You shouldn't set it. This code works for me

    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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM