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


roid Notification 通知栏点击不能跳转


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

先说下我遇到的问题:

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

1 Intent msgIntent =  new Intent();
2  
3 msgIntent.addCategory(Intent.CATEGORY_LAUNCHER);
4                         msgIntent.setComponent( new ComponentName(context.getPackageName(), "com.test.FragmentActivity"));
5  
6 msgIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); //  关键的一步,设置启动模式
7   
8 UITools.showNotification(context, Notify.NORMAL, msgIntent, jsonBean.getMessageTitle());

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

1 Intent msgIntent =  new Intent();
2  
3 msgIntent.setClass(context, FragmentActivity. class);
4  
5 msgIntent.setFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); //  关键的一步,设置启动模式
6   
7 UITools.showNotification(context, Notify.NORMAL, msgIntent, jsonBean.getMessageTitle());



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

1  < activity
2               android:name =".activity.FragmentActivity"
3              android:taskAffinity =""   >
4          </ activity >

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

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

1 Intent msgIntent =  new Intent();
2  
3 msgIntent.setAction(IntentAction.ACTION_TRIP_APPROVE);
4  
5 UITools.showNotificationBroadcast(context, Notify.NORMAL, msgIntent, jsonBean.getMessageTitle());   // 这里是发送广播哦


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

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



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

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



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

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

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



免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM