2015-10-05 106 views
0

我有一个通知,当我点击它时,打开我的应用程序。但我的应用程序在后台打开,通知抽屉仍然可见。我的通知本身被取消并删除,但抽屉仍然存在于所有内容之上。隐藏Notifaction抽屉打开时活动

通知类看起来是这样的:

public MyNotification(final Context context) { 
    this.context = context; 

    remoteView = new RemoteViews(context.getPackageName(), R.layout.notification); 

    notification = new Builder(context) 
      .setSmallIcon(R.drawable.notification_icon) 
      .build(); 

    notification.flags = Notification.FLAG_NO_CLEAR; 
    notification.priority = Notification.PRIORITY_MAX; 

    remoteView.setOnClickPendingIntent(R.id.container, getIntent(ACTION_OPEN_APP)); 

    notification.bigContentView = remoteView; 

    notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); 
    notificationManager.notify(MY_NOTIFICATION_ID, notification); 
} 

private PendingIntent getIntent(String action) { 
    Intent receiveIntent = new Intent(context, NotificationReceiver.class); 
    receiveIntent.setAction(action); 
    return PendingIntent.getBroadcast(context, 0, receiveIntent, 0); 
} 

我的接收器看起来像这样:

public class NotificationReceiver extends BroadcastReceiver { 

@Override 
public void onReceive(Context context, Intent intent) { 
    String action = intent.getAction(); 

    if(action.equalsIgnoreCase(AudioPlayerNotification.ACTION_OPEN_APP)) { 

     Intent openAppIntent = new Intent(context, MyActivity.class); 
     openAppIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); 
     context.startActivity(openAppIntent); 
    } 
} 

App in the backtround with notification drawer on top

我也有一个基地活动启动时删除通知活动。我错过了什么?

回答