android Notification 通知栏点击不能跳转(转自:http://www.oschina.net/question/778954_212394)

roid Notification 通知栏点击不能跳转

关于通知栏Notification的使用,不多讲,这里说的很清楚http://www.cnblogs.com/zenfly/archive/2012/02/09/2343923.html

先说下我遇到的问题:

在应用关闭的时候,发送通知到通知栏,点击通知栏能正常跳转到我想要的页面,代码如下

?


1

2

3

4

5

6

7

8

Intent msgIntent = new Intent();

msgIntent.addCategory(Intent.CATEGORY_LAUNCHER);

                        msgIntent.setComponent(new ComponentName(context.getPackageName(), "com.test.FragmentActivity"));

msgIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);// 关键的一步,设置启动模式

UITools.showNotification(context, Notify.NORMAL, msgIntent, jsonBean.getMessageTitle());

在应用打开的情况下,发送通知,代码如下:

?


1

2

3

4

5

6

7

Intent msgIntent = new Intent();

msgIntent.setClass(context, FragmentActivity.class);

msgIntent.setFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);// 关键的一步,设置启动模式

UITools.showNotification(context, Notify.NORMAL, msgIntent, jsonBean.getMessageTitle());

以上这段代码,出现了不能跳转的情况,于是,做了如下操作解决上述问题

?


1

2

3

4

<activity

            android:name=".activity.FragmentActivity"

            android:taskAffinity="" >

        </activity>

设置栈,可以正常响应我的通知栏意图了,但是新的问题出现了,当我按下Home键回到桌面的时候,在回来,就不能打开按下之间的页面了,不同的栈,,,,,

-------问题总是有的,于是换了一种折中的解决方案

?


1

2

3

4

5

Intent msgIntent = new Intent();

msgIntent.setAction(IntentAction.ACTION_TRIP_APPROVE);

UITools.showNotificationBroadcast(context, Notify.NORMAL, msgIntent, jsonBean.getMessageTitle());  //这里是发送广播哦

设置通知栏的意图为发送广播

?


1

PendingIntent pendingIntent = PendingIntent.getBroadcast(this, count, intent, PendingIntent.FLAG_UPDATE_CURRENT);

当然,这带来了新的问题,如果我的通知栏需要传递参数怎么办,可以通过如下方式传递

?


1

intent.setData(Uri.parse("abc"));

这种可以传递结构化的数据,那我们所谓的bundle就不能使用了么,当然不是,如下

?


1

PendingIntent pendingIntent = PendingIntent.getBroadcast(this, requestCode, intent, PendingIntent.FLAG_UPDATE_CURRENT);

PendingIntent pendingIntent = PendingIntent.getBroadcast(this, requestCode, intent, PendingIntent.FLAG_UPDATE_CURRENT);

标红的地方是重点,为每个意图设置不同的requestCode,Flag设置为更新当前

时间: 2024-08-06 19:32:06

android Notification 通知栏点击不能跳转(转自:http://www.oschina.net/question/778954_212394)的相关文章

Android Notification 通知栏点击不能跳转

先说下我遇到的问题: http://c.tieba.baidu.com/p/3466335206 http://c.tieba.baidu.com/p/3466336108 http://c.tieba.baidu.com/p/3466337185 在应用关闭的时候,发送通知到通知栏,点击通知栏能正常跳转到我想要的页面,代码如下 ? 1 2 3 4 5 6 7 8 Intent msgIntent = new Intent(); http://c.tieba.baidu.com/p/346633

Android Notification通知栏 下载控件

开启一个服务,服务中 启动一个通知. 通知中 下载. Android之Notification的多种用法 http://blog.csdn.net/loongggdroid/article/details/17616509 Android多任务下载,使用Notification更新进度条: http://cn23snyga.iteye.com/blog/1902071 Android4.1:通知栏显示可点击的按钮-Notification.builder Sample: http://blog.

Android Notification通知栏开发详解

Notification是在你的应用常规界面之外展示的消息.当app让系统发送一个消息的时候,消息首先以图表的形式显示在通知栏.要查看消息的详情需要进入通知抽屉(notificationdrawer)中查看.通知栏和通知抽屉(notificationdrawer)都是系统层面控制的,你可以随时查看,不限制于app. 图 1.通知栏的通知 图 2. notificationdrawer中的通知. Notification 的设计 作为android UI中很重要的组成部分,notification

android web页面点击事件跳转至APP

直接上代码 1.而对于点击链接后,能否直接打开,可以通过下面的代码来实现.前提条件:你得知道你的APP对应的打开协议,在<intent-filter>中设置scheme.如微信,协议为:weixin:// ,and so on... <!-- a标签的链接,设置为对应的下载链接:点击打开的动作,在click事件中注册 --> <a href="http://www.baidu.com" id="openApp">打开APP<

Android自定义通知布局Notification,点击Notification导航切换回原Activity

一个简单的应用场景:假如用户打开Activity以后,按Home键,此时Activity 进入-> onPause() -> onStop() 不可见.代码在此时机发送一个Notification到通知栏.当用户点击通知栏的Notification后,又重新onRestart() -> onStart() -> onResume() 切换回原Activity. package zhangphil.pendingintent; import android.os.Bundle; im

android Notification 的使用(锁定通知栏)

最近一直在研究 android ,并一边研究一边做应用.其中遇到了把程序通知常驻在 Notification 栏,并且不能被 clear 掉(就像android QQ一样)的问题.经过研究实现了其功能,现把 Notification 的使用总结如下: Notification 的使用需要导入 3 个类 1 2 3 import android.app.PendingIntent; import android.app.NotificationManager; import android.app

如何知道我在通知栏的展示的 Notification 被点击了?

在某些业务需求下,我们需要统计发出去的通知被点击的次数,但是察看 Notifycation 和 NotifycationManager 里面都没有相关方法来设置点击监听器! 那怎么办? Notifycation 本来就需要我们给他设置一个 Intent 来执行点击之后的动作,这个 Intent 通过 PendingIntent 赋予. 关于 PendingIntent 刚接触可能会觉得不理解,官方解释:A description of an Intent and target action to

使用Android点击按钮跳转页面

1.首先新建一个Android工程,命名为MyApp(名字可以自己随意起); 2.以原有的MainActivity.java文件为登录界面,然后在src文件中的包上面右击选择New目录下的Other中的Android Activity,选择BlankActivity,修改一个Activity的名字(自定义),我这里命名为BankActivity,点选finish然后新建完成一个返回页面;\ 3.接下来就要添加布局文件了,我们在res文件下的layout文件里先双击activity_main.xm

如何绑定android点击事件--跳转到另一个页面并实现关闭功能?

一.点击按钮跳转到另一个页面. eg:实现从一个页面点击跳转到另一个页面 1.首先在一个布局文件(.XML)中绘画了一个跳转按钮(id为btn1): <Button         android:id="@+id/btn1"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:tex