Sto tentando di inviare informazioni dalla notifica all'attività richiamata, mentre dalla mia attività ho ottenuto null.Android Notification PendingIntent Extras null
Il codice per la notifica è:
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());
}
codice per ottenere informazioni da intenti attività principale;
Bundle extras = getIntent().getExtras();
if (extras != null) {
long deviceID = getIntent().getLongExtra("ineedid",
-1);
if (ID == -1) {
if (D)
Log.i(TAG_D, "Wrong Id received.");
finish();
} else {
device = dataSource.getDeviceByID(deviceID);
if (D)
Log.i(TAG_D, "Get the id.");
}
} else {
if (D)
Log.d(TAG_D, "Bundle is null");
finish();
}
Ho verificato prima della notifica ricevere una notifica, fascio non è nullo, ed ha id extra. Mentre, quando ho provato a recuperarlo dall'intento, non c'è più. Aiuto.
Ho anche provato ad aggiungere "resultIntent.addFlags (Intent.FLAG_ACTIVITY_SINGLE_TOP);", ma non funziona. – antonio081014
C'è un motivo per cui non stai usando 'resultPendingIntent.getExtras()'? – PearsonArtPhoto
Ho appena creato quelle righe per verificare se il mio file in sospeso contiene gli extra, e ho verificato che ha ciò che ho inserito. – antonio081014