开发者

Android notification manager help

I m currently looking into android notification. Is there any way to show all the notification from an applicatio开发者_Go百科n as a single one with the number in android notifications window. Clicking on this will redirect the user to a view in the application with separate notifications. Also Is there any way to set the activity for each notifications so that the user will be redirected to the appropriate activity based on the notification clicked.


You could attach a custom layout to your notification, which contains a counter. And when event occurs increase the counter and update the notification. Similar like in example below:

   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;

To attach an activity to the notification:

        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;

Hope it will help.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜