Java 具有PendingEvent的Android通知的额外空值

Java 具有PendingEvent的Android通知的额外空值,java,android,android-intent,android-notifications,android-pendingintent,Java,Android,Android Intent,Android Notifications,Android Pendingintent,我试图在点击通知时向活动发送一个int-Extra。当我点击通知时,活动启动,但额外的总是空的 我检查了很多类似的问题,但它们没有帮助我解决问题。(我尝试使用onNewIntent(),但从未调用过)。我怎样才能成功地发送额外的 这是创建意图的广播接收器: public class EventAlarmNearReceiver extends BroadcastReceiver { @Override public void onReceive(Context context,

我试图在点击通知时向活动发送一个int-Extra。当我点击通知时,活动启动,但额外的总是空的

我检查了很多类似的问题,但它们没有帮助我解决问题。(我尝试使用onNewIntent(),但从未调用过)。我怎样才能成功地发送额外的

这是创建意图的广播接收器:

public class EventAlarmNearReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {

        Intent nextIntent = new Intent().setClass(context, EventActivity.class);
        nextIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
        int id = 1234;
        nextIntent.putExtra("Id", (long) id);
        nextIntent.setAction("nearReceiverAction");
        PendingIntent nextPendingIntent = PendingIntent.getActivity(context, 1022, nextIntent, PendingIntent.FLAG_UPDATE_CURRENT);

        String text = "Your " + intent.getStringExtra("Name") + " is starting soon. Please read your documents.";

        NotificationsDeliver.getInstance().sendNotification(context, "Meeting Mate", text, nextPendingIntent);
    }
}
这是NotificationsDeliver中发送通知的方法:

public void sendNotification(@NonNull Context context, String title, String text, PendingIntent pendingIntent ) {
        NotificationCompat.Builder builder = new NotificationCompat.Builder(context, CHANNEL_ID)
                .setSmallIcon(R.drawable.ic_event_note_white_24dp)
                .setContentTitle(title)
                .setContentText(text)
                .setPriority(NotificationCompat.PRIORITY_HIGH)
                .setVibrate(new long[] { 1000, 1000, 1000 })
                .setContentIntent(pendingIntent)
                .setAutoCancel(true);

        NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);

        // notificationId is a unique int for each notification that you must define
        notificationManager.notify(999, builder.build());
    }
这是来自EventActivity的onCreate方法:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Intent intent = getIntent();
    long id = intent.getLongExtra("id", 0);
}

我猜这是因为你把“id”这个词的大写字母写得不一样,而把它放在另一个字母上;比较:

nextentint.putExtra(“Id”,(long)Id);
//                  ^^^^
vs

long id=intent.getlongtextra(“id”,0);
//                            ^^^^
尝试对这两个词使用相同的大写字母