是否允许通知?

时间:2013-07-08 23:31:22

标签: android checkbox sharedpreferences android-preferences android-notifications

嘿,如果单击复选框(pref_opt1),我希望实现选项通过首选项允许或取消状态栏中的通知。我现在有这个代码

// prefer
         setPref.setOnClickListener(new Button.OnClickListener(){



                @Override

                public void onClick(View arg0) {

                    // TODO Auto-generated method stub

                    Intent intent = new Intent(

                            MainActivity    .this, 

                            settings.class);

                    startActivityForResult(intent, 0);

                }});



            checkPref();

        }



        @SuppressLint("NewApi")
        private void checkPref(){

            SharedPreferences myPref 

            = PreferenceManager.getDefaultSharedPreferences(

                    MainActivity.this);

            boolean pref_opt1 = myPref.getBoolean("pref_opt1", false); 


            if (pref_opt1){
                NotificationManager notifi = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
                Notification notification = new Notification.Builder(getApplicationContext())
                .setContentTitle("NOTIFICATION FIRST TO TRY")
                .setContentText("TRYYY THE FIRST NOTIFICATION")
                .setSmallIcon(R.drawable.icon_small_not)
                //.setLargeIcon(aBitmap)
                .setTicker("TRYYY")
                .build();

                notification.flags = Notification.FLAG_ONGOING_EVENT;
                Intent i = new Intent(MainActivity.this, MainActivity.class); 
                PendingIntent penInt = PendingIntent.getActivity(getApplicationContext(), 0 , i , 0);
                notifi.notify(215,notification);
                } else {
                    // Here how can i not display the notifications?
                }
        }

如何设置关闭通知?我需要创建一个类吗?我该怎么办?

0 个答案:

没有答案
相关问题