安卓app开发,通知栏消息? 5
Notification点击通知栏消息怎么能打开app。如果此时app正在后台运行怎么直接唤醒app我的代码如下:NotificationManagermanager=(...
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)
.setSmallIcon(icon)
.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就必须要跳转一个页面,如果不加那点击通知栏消息就没反应。怎么回事 展开
我的代码如下:
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)
.setSmallIcon(icon)
.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就必须要跳转一个页面,如果不加那点击通知栏消息就没反应。怎么回事 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询