I have added a checkbox preference in preferences.xml
. There is a settings.java
file which has defined all the preferences.
Now There is a seperate java file which displays a notification when a message comes in.
If the checkbox is true, I would like to make the notification silent.
if(PreferenceManager.getDefaultSharedPreferences(Receiver.mContext).getString(Settings.PREF_SILENT_MODE, "").equals("true"))
//Make the notification silent ie.
else
Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
notification.sound = alarmSound;
There is a TYPE_NOTIFICATION
method associated with Ringtone manager for notification type of sound. Is there a way to make this silent?
I know there is a way to make it silent using AudioManager. setRingerMode(AudioManager.RINGER_MODE_SILENT);
But here, ringtone manager is being used.
Edit--FIGURED IT OUT (flag is a boolean value which returned the checkbox preference result from SharedPreferences)
settings.java
file-
public boolean checksilentmode(Context mContext)
{
SharedPreferences prefs= PreferenceManager.getDefaultSharedPreferences(mContext);
return prefs.getBoolean(PREF_SILENT_MODE,DEFAULT_SILENT_MODE);
}
Another java file-
`if(flag) //if flag is true ie silent mode is enabled.
{
alarmSound=null;
}
else
{
alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
}
notification.sound = alarmSound;`