मैं अधिसूचना से जानकारी को आमंत्रित करने की कोशिश कर रहा हूं, जबकि मेरी गतिविधि से मुझे शून्य मिल गया।एंड्रॉइड अधिसूचना लंबित इंटेंट एक्स्ट्रा नल
अधिसूचना के लिए कोड है:
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());
}
कोड के लिए मुख्य गतिविधि में आशय से जानकारी प्राप्त;
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();
}
अधिसूचना अधिसूचित होने से पहले मैंने सत्यापित किया है, बंडल शून्य नहीं है, और इसमें अतिरिक्त आईडी है। जबकि, जब मैंने इसे मंशा से लाने की कोशिश की, तो यह चला गया। मदद। resultIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
नोटिस:: यदि आप resultIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
के रूप में जोड़ने यह काम नहीं करेगा
मैंने "resultIntent.addFlags (Intent.FLAG_ACTIVITY_SINGLE_TOP) जोड़ने का भी प्रयास किया;", लेकिन कोई काम नहीं। – antonio081014
कोई कारण नहीं है कि आप 'resultPendingIntent.getExtras() 'का उपयोग नहीं कर रहे हैं? – PearsonArtPhoto
मैंने अभी यह लाइनें बनाई हैं कि यह जांचने के लिए कि क्या मेरे लंबित इंटेंन्ट में अतिरिक्त है, और मैंने सत्यापित किया है कि मैंने वहां क्या रखा है। – antonio081014