关闭对话框通知在Android的共享preference

关闭对话框通知在Android的共享preference

本文介绍了关闭对话框通知在Android的共享preference的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我的共享preference在我的应用程序有铃声。

我想将禁用通知短信和彩信通知,像警报通知应用程序

 <?XML版本=1.0编码=UTF-8&GT?;
    < preferenceScreen的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android>
      <复选框preference
      机器人:标题=禁用通知
      机器人:设置defaultValue =真
      机器人:键=复选框
      机器人:总结=勾选/>   < / preferenceScreen>

这是我的对话框通知code之一:

  //警告code
    最后AlertDialog alertDialog =新AlertDialog.Builder(本).create();
        alertDialog.setTitle(复位...);
        alertDialog.setMessage(你确定?);        Alert.setOnClickListener(新View.OnClickListener(){
            公共无效的onClick(视图v){
                // TODO自动生成方法存根                alertDialog.setButton(OK,新DialogInterface.OnClickListener(){
                    公共无效的onClick(DialogInterface对话,诠释它){
                        //这里你可以添加功能
                    }
                });                alertDialog.setIcon(android.R.drawable.ic_dialog_alert);
                alertDialog.show();
            }
        });    }

我尝试运行它,但是当我用报警通知尝试没有成功。


解决方案

 共享preferences共享preferences = this.get preferences(MODE_PRIVATE);
布尔hideNotification =共享preferences.getBoolean(复选框,FALSE);如果(!hideNotification)
    alertDialog.show();

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

解决方案
SharedPreferences sharedPreferences = this.getPreferences(MODE_PRIVATE);
boolean hideNotification = sharedPreferences.getBoolean("checkbox", false);

if(!hideNotification)
    alertDialog.show();

这篇关于关闭对话框通知在Android的共享preference的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 11:06