Android notification putExtra() from Service
Unsolved
Mobile and Embedded
-
Hello!
I would like to get some extra data passed along within my notification, triggered from within my foreground service.
In the Service, I create an Intent and a PendingIntent. That works fine to trigger the notification. But I cannot seem to find a solution where I can pass extra information within the notification, to be opened when the user opens the app by clicking the notification.
Intent notificationIntent = new Intent(m_instance, org.qtproject.qt5.android.bindings.QtActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity(m_instance, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
I've tried adding:
notificationIntent.putExtra("test", "testing");
but I get NULL in my onCreate() method of the Service:
public void onCreate() { super.onCreate(); Log.i(TAG, "Creating Service"); m_instance = QtAndroidService.this; Intent i = new Intent(m_instance, org.qtproject.qt5.android.bindings.QtActivity.class); String extra = intent.getExtras().getString("test"); }
What am I not understanding?