Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
317 views
in Technique[技术] by (71.8m points)

android - Removing notification after click

I just started working with notifications and now I'm trying to remove the notification and launch the app once the notification has been tapped in the notificationcenter.

I tried to work with the following code:

import android.app.NotificationManager;

public class ExpandNotification {
     private int NOTIFICATION = 546;
     private NotificationManager mNM;

     public void onCreate() {
        mNM.cancel(NOTIFICATION);
        setContentView(R.layout.activity_on);
        //Toast.makeText(this, "stopped service", Toast.LENGTH_SHORT).show();
    }

I think this code executes the other class when tapped?

PendingIntent contentIntent = PendingIntent.getActivity(this, REQUEST_CODE, new Intent(this, ExpandNotification.class), 0);

However the notification doesn't go away, nor does the application launch. But I'm able to swipe it to left or right to remove it but that's not what I want..

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

To get the same effect using Notification.Builder or NotificationCompat.Builder call setAutoCancel(true) on the Builder instance.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...