我这边自动集成的方式添加极光推送,发送通知,自定义通知都能收到,但是后台触发的收不到,我是自定义设置的 下面是Android自定义代码,对后台参数有啥要求吗,比如json串必须传那个参数

Kris_Liu
2019-05-27 10:26 542 0

```
//send msg to MainActivity
private void processCustomMessage(Context context, Bundle bundle) {
String channelID = "1";
String channelName = "channel_name";

    // 获得系统推送的自定义消息
    String extras = bundle.getString(JPushInterface.EXTRA_EXTRA);
    Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), R.mipmap.reada_icon);

    Intent mIntent = new Intent(context, TestActivity.class);

// ThirdView.isReadList = false;
mIntent.putExtras(bundle);
mIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, mIntent, 0);

    NotificationManager notificationManager = (NotificationManager) context.getSystemService(NOTIFICATION_SERVICE);

    //适配安卓8.0的消息渠道
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        NotificationChannel channel = new NotificationChannel(channelID, channelName, NotificationManager.IMPORTANCE_HIGH);
        notificationManager.createNotificationChannel(channel);
    }

    NotificationCompat.Builder notification =
            new NotificationCompat.Builder(context, channelID);

    notification.setContentIntent(pendingIntent)
            .setAutoCancel(true)
            .setContentText("我是内容")
            .setContentTitle("自定义Title")
            .setSmallIcon(R.drawable.icon_audio)
            .setDefaults(Notification.DEFAULT_ALL);
    notification.setSound(Uri.parse("android.resource://" + context.getPackageName() + "/" + R.raw.test));
    notificationManager.notify((int) (System.currentTimeMillis() / 1000), notification.build());
}

1个回答

热门排序