Próbuję wysyłać informacje z powiadomienia do wywoływanej aktywności, podczas gdy z mojej aktywności uzyskałem wartość null.Powiadomienie o Androidzie Oczekujące dodatki null
Kod do zgłoszenia jest:
private void showNotification() {
Intent resultIntent = new Intent(this, MainActivity.class);
if (D)
Log.d(TAG, "Id: " + Id);
resultIntent.putExtra("ineedid", deviceId);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
stackBuilder.addParentStack(MeterActivity.class);
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,
PendingIntent.FLAG_UPDATE_CURRENT);
// Bundle tmp = resultIntent.getExtras();
// if (tmp == null) {
// Log.d(TAG, "tmp bundle is null");
// } else {
// long id = tmp.getLong("ineedid", -1);
// Log.d(TAG, "tmp id : " + id);
// }
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
BLEMessengerService.this)
.setSmallIcon(R.drawable.ic_action_search)
.setContentTitle("Event tracker")
.setContentText("Events received").setOngoing(true)
.setContentIntent(resultPendingIntent)
.setWhen(System.currentTimeMillis());
int mId = R.string.service_notification_start_service;
mNM.notify(mId, mBuilder.getNotification());
}
Kod uzyskać informacje z zamiarem aktywności głównego;
Sprawdziłem przed otrzymaniem powiadomienia powiadomienia, pakiet nie jest pusty i ma identyfikator w dodatkach. Podczas gdy próbowałem go pobrać z intencji, zniknęło. Wsparcie.
Próbowałem również dodać "resultIntent.addFlags (Intent.FLAG_ACTIVITY_SINGLE_TOP);", ale bez pracy. – antonio081014
Istnieje powód, dla którego nie używasz 'resultPendingIntent.getExtras()'? – PearsonArtPhoto
Właśnie wykonałem te linie, aby sprawdzić, czy mój oczekujący intendent ma dodatki, i zweryfikowałem, że ma to, co tam umieściłem. – antonio081014