2017-09-04 3 views
0

BroadcastReceiverで通知にチェックボックスを使用したいと思います。すべてチェックボックスを設定しましたが、振動を止められず、通知を制御できません。私は振動を止めたい。チェックボックスの基準は間違っている。チェックボックスの基準が真である。私の電話を振動させる。どうすればいいの?CheckboxPreferenceでbroadcastReceiverを使用して通知する

<?xml version="1.0" encoding="utf-8"?> 
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> 


    <CheckBoxPreference 
     android:defaultValue="true" 
     android:key="vibrate" 
     android:summary="Telefona görev geldiğinde titreşim yollanır." 
     android:title="Titreşim" 
    > 
    </CheckBoxPreference> 
    <CheckBoxPreference 
     android:defaultValue="true" 
     android:key="notify" 
     android:summary="Telefona görev geldiğinde ses ile uyarılır." 
     android:title="Bildirim sesi" 
     > 
    </CheckBoxPreference> 


</PreferenceScreen> 

マイセッティング活動(そうPreferenceActivity):

public class Ayarlar extends PreferenceActivity { 


    boolean autovibrate; 

    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     addPreferencesFromResource(R.xml.settings); 
getListView().setBackgroundColor(getResources().getColor(R.color.yüz));} 


    public void onStart(Intent intent, int startId) { 
     getPrefs(); 
    } 

    private void getPrefs() { 
     SharedPreferences prefs = PreferenceManager 
       .getDefaultSharedPreferences(getBaseContext()); 

     autovibrate = prefs.getBoolean("vibrate", true); 
    } 


    } 

マイbroadcastReceiver:

public class Alarm extends BroadcastReceiver { 
     cancelAlarm(context); 

      setalarm(context); 
    } 
    It is in a if loop. 
     Notification noti = null; 
       if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) { 
        noti = new Notification.Builder(context) 
          .setTicker(" size bir bildirim yolladı.") 
          .setContentTitle("") 
          .setContentText(listData.get(secilmissayı) + " i arama zamanı") 
          .setSmallIcon(R.drawable.alarm_24dp) 

          .addAction(R.drawable.cal, "Ara", pendingIntentYes) 
          .addAction(R.drawable.se, "Daha Sonra", pendingIntentYes2) 

          .setContentIntent(pIntent).getNotification(); 
       } 

       NotificationManager notificationManager = (NotificationManager) context.getSystemService(NOTIFICATION_SERVICE); 
       noti.flags |= Notification.FLAG_AUTO_CANCEL; 
       noti.defaults |= Notification.DEFAULT_ALL; 

       noti.defaults |= Notification.DEFAULT_VIBRATE; 

       notificationManager.notify(0, noti); 
I tried achive settings activity     
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context); 




      } 

答えて

1

はあなたのように見えます

マイ設定XML(私はPreferenceactivityでbegginnerています)共有された嗜好からの振動を原因とする属性を取得する必要があります。それは価値変更の通知設定です。アラームクラスのコードに追加します。

SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); 
Boolean vibrate = prefs.getBoolean("vibrate", true); 

noti.defaults |= Notification.DEFAULT_SOUND; 
if (vibrate) { 
    noti.defaults |= Notification.DEFAULT_VIBRATE; 
} 
関連する問題