Android 通知栏Notification点击跳转无效

来源:互联网 发布:c语言编写界面 编辑:程序博客网 时间:2024/06/06 07:11
一定要保证
notificationManager.notify(0,builder.build());

这段代码写在setContentIntent()方法之后否者无效.


之前点击无效的代码是这样写的---->错误的方法:

notificationManager.notify(0,builder.build());//点击通知栏跳转到聊天界面        Intent intent = new Intent(this,ChatActivity.class);        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);        builder.setContentIntent(pendingIntent);

修改后--->正确的方然:

//点击通知栏跳转到聊天界面        Intent intent = new Intent(this,ChatActivity.class);        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);        builder.setContentIntent(pendingIntent);notificationManager.notify(0,builder.build());



0 2
原创粉丝点击