Notificationが自動的に消える方法をクリックします.


Notificationをクリックして自動的に消える方法:文を追加します.settAutoCancel(true)でいいです.
次のコードに示します.
 public class TestAty extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
    

        final NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

        super.onCreate(savedInstanceState);
        setTitle(" ");
        setContentView(R.layout.aty_test);
        

        Button btnNotify = (Button) findViewById(R.id.btnNotification);
        btnNotify.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                Context context = getApplicationContext();
                CharSequence contentTitle = " ";
                CharSequence contentText = " ";
                Intent intent = new Intent(TestAty.this, MainAty.class);
                PendingIntent contentIntent = PendingIntent.getActivity(TestAty.this, 0,
                        intent, 0);
                        

                Notification notification = new Notification.Builder(context)
                        .setContentTitle(contentTitle)
                        .setContentText(contentText)
                        .setSmallIcon(R.drawable.test_icon_2)
                        .setWhen(System.currentTimeMillis())
                        .setDefaults(Notification.DEFAULT_ALL)
                        .setContentIntent(contentIntent)
                        .setAutoCancel(true)
                        .build();
                        


                // mNotificationManager notify 
                notificationManager.notify(1, notification);
            }
        });
    }
}