android通知栏的消息内容,怎么得到和保存消息。
解决方案 »
- 如何修改CPU核心数?
- 为什么返回上一步,要两次才能退出Activity
- 多个service同时运行其中一个service出现Exception会导致所有的service都停止吗
- 【请教】android有封装了socket的lib吗?像ipworks的ipport类那样的
- 使用安卓长按录音,弹起结束要用到哪些
- jjs如何调用打开android apk 应用
- 奇怪:LinearLayout 后续不能追加 View 成员!
- 求助 网络视频播放。。。
- 关于android的声音采样
- Android Camera后摄像头视频传输显示左右mirror
- 请问还有别的方法去调用其他程序的功能吗?
- android 中handleMessage和dispatchMessage的区别?
NotificationManager nm = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
PendingIntent pendingIntent = null;
if (!TextUtils.isEmpty(message.getJump())) {//这里的message是个实体类,就是一些属性
Intent intent = new Intent(context, MessageActivity.class);//点击通知栏跳转到指定界面
if (message.getParameter() != null) {
Bundle bundle2 = new Bundle();
bundle2.putString("title", message.getTitle());
bundle2.putString("content", message.getContent());
intent.putExtras(bundle2);//数据放入到intent
}
pendingIntent = PendingIntent.getActivity(context, 0,
intent, PendingIntent.FLAG_ONE_SHOT);//再将intent放入pendingIntent
}
Notification baseNF = new Notification.Builder(context)
.setAutoCancel(true)
.setContentTitle(message.getTitle())
.setContentText(message.getContent())
.setTicker(message.getTitle())
.setDefaults(Notification.DEFAULT_SOUND| Notification.DEFAULT_VIBRATE)
.setContentIntent(pendingIntent)//这里将pendingIntent放入
.setSmallIcon(R.drawable.bar_icon)
.setWhen(System.currentTimeMillis()).build();
nm.notify(0, baseNF);//最后发出通知栏baseNF
//在MessageActivity中
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = getIntent();
if(intent!=null){
Bundle bundle2 = intent.getExtras();
if(bundle2!=null){
// 获取该Intent所携带的数据
String title = bundle2.getString("title");
String content = bundle2.getString("content");
}
}
}
//如果你的MessageActivity是单例模式,还需要重写
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
if(intent!=null){
Bundle bundle2 = intent.getExtras();
if(bundle2!=null){
// 获取该Intent所携带的数据
String title = bundle2.getString("title");
String content = bundle2.getString("content");
}
}
}