自定义通知 [英] Custom Notification

查看:130
本文介绍了自定义通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有使用商品通知栏,以便做一些操作(的onClick)的一种方式,而不必被推出了一个活动/恢复。

例如..比方说,我养notifcation,并在其上​​的用户preSS的话,而不是带我去一些活动,它在我的当前活动/服务调用一些正规方法

有没有什么办法来实现这样的事?

例如当前notifcation code做一个非标准的行为的onClick。运行了一个活动..怎么会channge的code,以便调用活动的一些方法来代替?

  messagesManager =(NotificationManager)
               context.getSystemService(Context.NOTIFICATION_SERVICE);


    通知通知=新的通知(R.drawable.icon,消息,
            System.currentTimeMillis的());
    PendingIntent contentIntent = PendingIntent.getActivity(上下文,0,
            新意图(上下文,someActivity.class),0);
    notification.setLatestEventInfo(背景下,通知的消息,
            contentIntent);
    messagesManager.notify(R.string.noto,通知);
 

解决方案
  

有没有办法实现这样的   事?

使用适当的 PendingIntent 。而不是调用的 getActivity(),呼叫的getService() getBroadcast()

I would like to know if there is a way of using the notication bar in order to do some operations (onClick), without having an activity being launched/resumed.

for example.. let's say i raise a notifcation, and when the user press on it, then instead of take me to some activity, it invoke some regular method in my current activity/service

Is there any way to implement such a thing?

for example the current notifcation code do a standart behave onClick. running up an activity.. how will channge the code in order to invoke some method instead of an activity?

        messagesManager = (NotificationManager) 
               context.getSystemService(Context.NOTIFICATION_SERVICE);


    Notification notification = new Notification(R.drawable.icon, message,
            System.currentTimeMillis());
    PendingIntent contentIntent = PendingIntent.getActivity(context, 0,
            new Intent(context, someActivity.class), 0);
    notification.setLatestEventInfo(context, "notification", message,
            contentIntent);
    messagesManager.notify(R.string.noto, notification);

解决方案

Is there any way to implement such a thing?

Use an appropriate PendingIntent. Instead of calling getActivity(), call getService() or getBroadcast().

这篇关于自定义通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆