我正在尝试将我的复选框偏好设置与我的通知相关联,这样当用户点击任何复选框偏好设置时,通知按指定的方式工作。我希望"进入"仅在首选项"警报进入"点击。同样适用于退出和振动。
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
String key = LocationManager.KEY_PROXIMITY_ENTERING;
Boolean entering = intent.getBooleanExtra(key, false);
if (entering){
Log.d(getClass().getSimpleName(), "entering");
}
else{
Log.d(getClass().getSimpleName(), "exiting");
}
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
String alertName = prefs.getString("name_preference", "");
String alertMessage = prefs.getString("message_preference", "");
//boolean enteringRegion = prefs.getBoolean("alarm_entering", true);
//boolean exitRegion = prefs.getBoolean("alarm_exiting", false);
//boolean vibrate = prefs.getBoolean("vibrate_preference", true);
NotificationManager notificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, null, 0);
Notification notification = createNotification();
notification.setLatestEventInfo(context, alertName, alertMessage, pendingIntent);
notificationManager.notify(NOTIFICATION_ID, notification);
}
private Notification createNotification(){
Notification notification = new Notification();
notification.icon = R.drawable.icon_notification;
notification.when = System.currentTimeMillis();
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notification.flags |= Notification.FLAG_SHOW_LIGHTS;
notification.defaults |= Notification.DEFAULT_LIGHTS;
long[] vibrate = new long[] {2000, 2000, 2000, 2000, 2000};
notification.vibrate = vibrate;
Uri ringURI = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
notification.sound = ringURI;
notification.ledARGB = Color.BLUE;
notification.ledOnMS = 1500;
notification.ledOffMS = 1500;
notification.flags = notification.flags | Notification.FLAG_SHOW_LIGHTS;
return notification;
答案 0 :(得分:0)
我会这样尝试:
myPrefListner = new OnSharedPreferenceChangeListener()
{
public void onSharedPreferenceChanged(SharedPreferences prefs, String key)
{
//check if alarm key is set as wanted and if so launch notification
}
};
但我不太确定“进入”是什么意思?