0

嘿,如果单击复选框(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?
                }
        }

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

4

0 回答 0