2012-04-11 14 views
2

我樂享優先共享偏好禁用對話框通知..在我的應用程序有鈴聲的Android

我想要把禁用通知短信,彩信和通知,像警報通知應用程序

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

    } 

我嘗試運行它,但是當我與報警通知嘗試沒有成功

+0

真的嗎?沒有答案? – user1257040 2012-04-11 18:43:54

回答

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

if(!hideNotification) 
    alertDialog.show(); 
+0

你可以告訴我,我應該把這段代碼放在onDestroy()中嗎?或onStart()? – Maha 2012-04-11 22:28:22

+0

'onCreate()' – 2012-04-12 16:23:50

+0

裏面,但我有一個onStart()的鈴聲,所以禁用通知和鈴聲將正常工作? – Maha 2012-04-12 16:46:03

相關問題