2017-01-12 1 views
0

私のアプリはワンタイムアラームを作ります。アラームがオフになると、通知が表示され、電話が振動しています。通知が表示され、viabratorは正常に動作します。既に設定されている通知でバイブレータを無効にする

アプリ設定では、既に設定されている通知でユーザーがviabratorを非アクティブにできるようにします。 Settings

誰もがこのために良い解決策を持っていますか?画像に表示されているボタンにコードを追加するためのソリューションです。

// 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

関連する問題