Oracle Help Center | Oracle Push Cloud Service (Standalone) title

Passing Extra Data

Deep Linking via Pressed Notifications:

If you are using the PushIOActivityLauncher, you are expected to pass the notification intent (from the BroadcastReceiver) as extras:

Intent newIntent = new Intent(this, PushIOActivityLauncher.class);
newIntent.putExtras(intent);
PendingIntent.getActivity(this, 0, newIntent, PendingIntent.FLAG_UPDATE_CURRENT);

NOTE: Using FLAG_UPDATE_CURRENT will ensure that the newest set of intent extra gets used over the older extra intents.

You must register an intent filter in your AndroidManifest.xml file, so that when an app user presses a notification that uses the PushIOActivty launcher, an intent is broadcast for the action ${applicationId}.NOTIFICATIONPRESSED. To register the intent filter, add the following to your AndroidManifest.xml file:

<activity android:name="${applicationId}.YourActivity">
    <intent-filter>
        <action android:name="${applicationId}.NOTIFICATIONPRESSED"/>
        <category android:name="android.intent.category.DEFAULT"/>
    </intent-filter>
</activity>

From here, using the getStringExtra method, you can direct a user to a certain internal page or external link when they press/engage the notification.


getStringExtra Sample Code:

This sample code uses two extra key/pairs (alert, details) to build a notification based off the details of those extras.

public class NotificationBroadcastReceiver extends BroadcastReceiver {

private NotificationManager mNotificationManager;
private int SIMPLE_NOTIFICATION_ID;

public void onReceive(Context context, Intent intent) {
if (intent != null) {
for( String t :intent.getExtras().keySet()) {
try {
Log.d("class", "extra key: " + t + " value: " +
intent.getStringExtra(t));
} catch (Exception e ){
Log.d("class", "Not a string", e);
}
}
}
mNotificationManager = (NotificationManager)
context.getSystemService(Context.NOTIFICATION_SERVICE);

Intent newIntent = new Intent(context,
PushIOActivityLauncher.class);
newIntent.putExtras(intent);

for( String t :newIntent.getExtras().keySet()) {
try {
Log.d("class", "newIntent extra key: " + t + " value: " +
newIntent.getStringExtra(t));
} catch (Exception e ){
Log.d("class", "Not a string", e);
}
}

PendingIntent.getActivity(this, 0, newIntent, PendingIntent.FLAG_UPDATE_CURRENT);

NotificationCompat.Builder notify = new
NotificationCompat.Builder(context);
notify.setSmallIcon(R.drawable.ic_logo)
.setWhen(System.currentTimeMillis())
.setTicker(intent.getStringExtra("alert"))
.setContentIntent(lPendingIntent)
.setContentTitle(intent.getStringExtra("alert"))
.setContentText(intent.getStringExtra("details"))
.setAutoCancel(true);

mNotificationManager.notify(SIMPLE_NOTIFICATION_ID, notify.build());
Bundle extras = getResultExtras(true);
extras.putInt(PushIOManager.PUSH_STATUS,
PushIOManager.PUSH_HANDLED_NOTIFICATION);
setResultExtras(extras);
}
}