sky86768657 2020-03-09 14:09 采纳率: 0%
浏览 1284

安卓app开发,点击通知栏消息怎么能直接进入后台的app,不跳转页面

Notification 点击通知栏消息怎么能打开app。如果此时app正在后台运行怎么直接唤醒app

我的代码如下:

NotificationManager manager = (NotificationManager)activity.getSystemService(Context.NOTIFICATION_SERVICE);
int icon = R.mipmap.ic_logo;
String tickerText = "aaaaaaa"; //状态栏显示的通知文本提示
long when = System.currentTimeMillis(); //通知产生的时间,会在通知信息里显示
String contentTitle = "title"; //通知栏标题
String contentText = "aaaaaaa"; //通知栏内容

Intent intent = new Intent(activity, DevicelistActivity.class); //点击该通知后要跳转的Activity
PendingIntent contentIntent = PendingIntent.getActivity(activity,0,intent,0);

Notification.Builder builder = new Notification.Builder(activity)

.setTicker(tickerText)
.setWhen(System.currentTimeMillis())
.setContentTitle(contentTitle)
.setContentText(contentText)
.setContentIntent(contentIntent)
.setDefaults(Notification.DEFAULT_SOUND);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){
String channelId = "ChannelId";
builder.setChannelId(channelId);
NotificationChannel channel = new NotificationChannel(
channelId,
"ChannelId",
NotificationManager.IMPORTANCE_DEFAULT);
manager.createNotificationChannel(channel);
}
Notification myNotify = builder.build();
myNotify.flags = Notification.FLAG_AUTO_CANCEL;
manager.notify(1, myNotify);

但是这样写会导致点击通知栏发过来的消息,会跳转进入DevicelistActivity页面,如果我删除了
Intent intent = new Intent(activity, DevicelistActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(activity,0,intent,0);

这两行代码的话,那点击通知栏消息就没有任何反应。。。

我现在需要点击通知栏消息,直接开启app 或者将app从后台唤醒显示出来就行,不需要跳转到任何页面。他进入后台前是什么页面 点击通知栏直接显示那个页面就行,不需要跳转。。不知道怎么才能做到,如果加intent就必须要跳转一个页面,如果不加那点击通知栏消息就没反应。怎么回事

希望大佬可以指定一下,谢谢

  • 写回答

4条回答 默认 最新

  • zqbnqsdsmd 2020-03-09 22:11
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办