2017-01-12 88 views
0

我的應用正在發出一次性警報。當鬧鈴響起時,通知會顯示,手機正在振動。通知顯示,並且viabrator工作正常。在已設置的通知中關閉振動器

在應用程序設置中,我想允許用戶在已設置的通知中禁用viabrator。 Settings

有沒有人有這方面的很好的解決方案。一個解決方案,將允許我添加一些代碼到圖片中顯示的按鈕onclick。

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

回答

1

如果你發送一個新的通知,同樣的ID,它會覆蓋原來的。因此,請採取相同的通知,關閉振動,並使用該ID發佈。

+1

很酷,我會試試看。 – TheDave