Android通知管理器帮助

Dij*_*vid 3 notifications android notificationmanager

我目前正在研究android通知.有没有办法在Android通知窗口中显示来自应用程序的所有通知作为单个通知.单击此按钮将使用单独的通知将用户重定向到应用程序中的视图.是否有任何方法可以为每个通知设置活动,以便根据单击的通知将用户重定向到相应的活动.

ack*_*kio 6

您可以将自定义布局附加包含计数器的通知中.当事件发生时,增加计数器并更新通知.类似于下面的示例:

   Notification notification = new Notification(R.drawable.logo, name,    System.currentTimeMillis());

   RemoteViews contentView = new RemoteViews(appContext.getPackageName(), R.layout.custom_layout );

   contentView.setTextViewText(R.id.notification_text, Counter);

notification.contentView = contentView;
Run Code Online (Sandbox Code Playgroud)

要将活动附加到通知:

        Intent notificationIntent = new Intent(appContext, MyActivity.class);
        Bundle bundle = new Bundle();
        bundle.putInt(...);
        notificationIntent.putExtras( bundle );
        notificationIntent.setFlags( Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);           

        PendingIntent contentIntent = PendingIntent.getActivity( appContext, (int)System.currentTimeMillis(), notificationIntent, 0 );
        notification.contentIntent = contentIntent;
Run Code Online (Sandbox Code Playgroud)

希望它会有所帮助.