问题
i have Shared preference in my application that has Ringtone ..
i wanna to put Disable Notification SMS and MMS and notification from the app like alarm notification
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<CheckBoxPreference
android:title="Disable Notification"
android:defaultValue="true"
android:key="checkbox"
android:summary="Check the Box"/>
</PreferenceScreen>
This is one of my dialog notification code:
//Alert Code
final AlertDialog alertDialog = new AlertDialog.Builder(this).create();
alertDialog.setTitle("Reset...");
alertDialog.setMessage("Are you sure?");
Alert.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// here you can add functions
}
});
alertDialog.setIcon(android.R.drawable.ic_dialog_alert);
alertDialog.show();
}
});
}
i try to run it, but when i try with alarm notification it did not work
回答1:
SharedPreferences sharedPreferences = this.getPreferences(MODE_PRIVATE);
boolean hideNotification = sharedPreferences.getBoolean("checkbox", false);
if(!hideNotification)
alertDialog.show();
来源:https://stackoverflow.com/questions/10110926/disable-dialog-notification-in-shared-preference-in-android