我在共享首选项中存储了无线电组的值,现在我想在 android 中使用该值进行通知

I had stored values of radio group in shared preference now I want to use that values for notification in android

例如,如果用户选择关闭振动的单选按钮,则在收到通知时,必须使用 NotificationCompat.Builder

关闭振动

谁能给我个主意?

很简单。

1.在显示通知之前,在共享首选项的帮助下检查振动是开还是关。

SharedPreferences settings;
settings = getSharedPreferences("PREFS_NAME", 0); //Initialize SharedPreferences

Boolean CheckVibration = settings.getBoolean("CheckVibration", true); 
//checks the vibration is ON or OFF through Sharedpreferences

2。显示通知

NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this);
mBuilder.setContentTitle(getString(R.string.app_name));
mBuilder.setContentText("Notification Testing!");

if(CheckVibration){
  long[] v = {100,200}; //The first index of array is number of milliseconds to wait before turning the vibrator on and the second index is number of millisecond to vibrate before turning it off
  mBuilder.setVibrate(v); // if vibration is ON by RadioGroup, It will be Vibrate
}


NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(notifiid, mBuilder.build());

3。不要忘记在 AndroidManifest.xml.

中允许 VIBRATE 权限

<uses-permission android:name="android.permission.VIBRATE" />

快乐编码:)