2017-09-04 6 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); 
    } 


    } 

내 브로드 캐스트 리시버 :

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입니다) 공유 환경 설정 및 진동에 따라 진동을 담당하는 속성을 가져와야합니다. 그것에 가치 변화 알림 설정. 이를 Alarm 클래스의 코드에 추가하십시오.

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

noti.defaults |= Notification.DEFAULT_SOUND; 
if (vibrate) { 
    noti.defaults |= Notification.DEFAULT_VIBRATE; 
}