Disable Dialog Notification in Shared Preference in android

时间秒杀一切 提交于 2019-12-12 21:00:38

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!