簡體   English   中英

Android:單擊后隱藏我的提醒通知

[英]Android: Hide my reminder notification when it has been clicked

我的Android應用程序中有一個通知系統,通知時間到了時,通知欄上會顯示我的通知,當用戶單擊它時,我的應用程序會打開,但通知欄上仍會顯示通知。 用戶單擊通知欄時如何隱藏通知欄?

public class AlarmReceiver extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {
    Calendar now = GregorianCalendar.getInstance();      
    Bundle bund = intent.getExtras();
    String text = bund.getString("name", "");
        Notification.Builder mBuilder = 
                new Notification.Builder(context)
                .setSound(android.provider.Settings.System.DEFAULT_NOTIFICATION_URI)
                .setSmallIcon(R.drawable.ic_launcher)
                .setContentTitle( text)
                .setContentText("text");
        Toast.makeText(context,"ok", Toast.LENGTH_LONG).show();
        Intent resultIntent = new Intent(context, Main.class);
        TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
        stackBuilder.addParentStack(Main.class);
        stackBuilder.addNextIntent(resultIntent);
        PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
        mBuilder.setContentIntent(resultPendingIntent);
        NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        mNotificationManager.notify(1, mBuilder.build());
   // }
}

}

你會嘗試嗎?

mBuilder.setAutoCancel(true);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM