Android 通知栏Notification点击跳转无效

一定要保证
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());



你可能感兴趣的:(Android 通知栏Notification点击跳转无效)