TheDave
TheDave

Reputation: 31

Deactivate vibrator in already set notifications

My app is making one-time alarms. When the alarm goes off, a notification shows and the phone is vibrating. The notification is shown and the viabrator works fine.

In the app settings I want to allow the user to deactivate the viabrator in the already set notifications. Settings

Does anybody have good solution for this. A solution that will allow me to add some code to the buttons onclick shown in the picture.

//Thx

public class AlarmReceiver extends BroadcastReceiver {                                                                     


@Override                                                                                                              
public void onReceive(Context context, Intent intent) {                                                                
        System.out.println("Broadcast receiver: " + context + intent);                                                 
        PendingIntent pIntent = PendingIntent.getActivity(context, 0, new Intent(context, MainActivity.class), 0);     

        // Build notification                                                                                          
        Notification noti = new Notification.Builder(context)                                                          
                .setContentTitle("13:00" + " Bla Bla Bla")                                              
                .setContentText("You have " + 0 + " Bla Bla." )                                           
                .setSmallIcon(R.drawable.helpicon)                                                                     
                .setContentIntent(pIntent)                                                                             
                .setVibrate(new long[] { 0, 1000, 1000, 1000, 1000 })                                                  
                .addAction(R.drawable.ic_add_alert_black_24dp, "Postpone", pIntent)                                    
                .addAction(R.drawable.ic_close_black_24dp, "Cancel", pIntent)                                          
                .addAction(R.drawable.ic_check_black_24dp, "Intake", pIntent).build();                                 
        NotificationManager notificationManager = (NotificationManager) context.getSystemService(NOTIFICATION_SERVICE);
        // hide the notification after its selected                                                                    
        noti.flags |= Notification.FLAG_AUTO_CANCEL;                                                                   
        notificationManager.notify(0, noti);                                                                           
}                                                                                                                      
}                                                                                                                          

Upvotes: 0

Views: 47

Answers (1)

Gabe Sechan
Gabe Sechan

Reputation: 93599

If you send a new notification with the same ID, it will override the original. So take the same notification, turn off vibration, and post it with that id.

Upvotes: 1

Related Questions