Pass extra parameters via gcm (google cloud message) - Cordova

2

When I send a notification to gcm , I added a parameter in the url called 'appUrl'. And when I open my Cordova app, I need to pass this parameter to index.html so that I can redirect my application to your devitor instead.

However, in the case below I always get null . If no MainActivity , I pass the direct value, without the intervention of a variable, it works normally.

GCMIntentService.java

public void createNotification(Context context, Bundle extras)
{
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    String appName = getAppName(this);
    String appUrl = extras.getString("appUrl");

    Intent notificationIntent = new Intent(this, PushHandlerActivity.class);

    notificationIntent.putExtra("appUrl", appUrl);

    notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
    notificationIntent.putExtra("pushBundle", extras);

    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);

    int defaults = Notification.DEFAULT_ALL;

    if (extras.getString("defaults") != null) {
        try {
            defaults = Integer.parseInt(extras.getString("defaults"));
        } catch (NumberFormatException e) {}
    }

    NotificationCompat.Builder mBuilder =
        new NotificationCompat.Builder(context)
            .setDefaults(defaults)
            .setSmallIcon(context.getApplicationInfo().icon)
            .setWhen(System.currentTimeMillis())
            .setContentTitle(extras.getString("title"))
            .setTicker(extras.getString("title"))
            .setContentIntent(contentIntent)
            .setAutoCancel(true);

MainActivity.java

public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);

    Bundle extras = getIntent().getExtras();
    String appUrl = extras.getString("appUrl");

    // Set by <content src="index.html" /> in config.xml
    loadUrl(launchUrl + "?app_url=" + appUrl);
}
    
asked by anonymous 26.06.2015 / 04:30

1 answer

1

Try to override this Method in your Activity:

protected void onNewIntent(Intent intent)

Documentation: link

    
01.07.2015 / 20:29