2

我在具有铃声的应用程序中具有共享偏好..

我想禁用通知短信和彩信以及来自应用程序的通知,例如警报通知

 <?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>

这是我的对话通知代码之一:

    //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();
            }
        });

    }

我尝试运行它,但是当我尝试使用警报通知时它不起作用

4

1 回答 1

1
SharedPreferences sharedPreferences = this.getPreferences(MODE_PRIVATE);
boolean hideNotification = sharedPreferences.getBoolean("checkbox", false);

if(!hideNotification)
    alertDialog.show();
于 2012-04-11T19:10:52.130 回答