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

Asked

Viewed 135 times

2

When sending a notification to gcm, I added a parameter to the url named 'appUrl'. And I need, when opening my Cordova app, to pass this parameter to the index.html so that I can redirect my application to its rightful place.

However, in the case below always receive null.
If in the MainActivity, i pass the direct value, without intervention of a variable, 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);
}
  • You are sending the parameter to the Activity correct? Because in your code you are passing the parameter to PushHandlerActivity and not MainActivity.

  • Can I send another Switch to Mainactivity? I believe that removing this Switch from Pushhandler will not work. Is there any other way to pass extras.getString("appUrl") to Mainactivity?

  • By your code I understood that you are sending the information in the correct way, but to the incorrect destination.

  • You’re not passing the "appUrl" to MainActivity therefore the MainActivity does not receive "appUrl".

  • I created another link and sent it to Mainactivity and I couldn’t compile the app. 'cannot find Symbol Mainactivity'... Sorry if I’m missing something simple. Crawling in java/android. :/

  • 1

    Dude, as long as you’re talking about GCM, does it guarantee fidelity in the delivery of messages? Is it in real time? and order is preserved?

  • The order is preserved yes. And the weather is very good. Very nice result.

Show 2 more comments

1 answer

1


  • Na Mainactivity?

  • 1

    That! in the Activity that will host the Bundle

  • So would it be within onNewIntent that I would start my app with loadUrl? That’s it?

  • After onCreate, I override the method: http://paste.ofcode.org/JcYvPybxk66nPnMNxAKeK . But now I can’t compile.

  • Symbol: class Intent Location: class Mainactivity Note: Some input files use or override a deprecated API.

  • You are compiling with which version of Android you are compiling?

  • android 4.0.0.. Just to reinforce.. I’m using Ordova, ok?

  • http://raphael-lemaire.com/phonegapjavadocs/com/phonegap/DroidGap.html#onNewIntent(Intent)

  • What Thiago sent, says I have to overwrite.. But when I overwrite, I can’t compile my app.

  • @Rafaelsoufraz, post the error, maybe I can help... I tried to research something specific, but I found nothing! Hugs

  • Did you ever see the code I posted on Past.ofcode? Is it to add this method in Mainactivity? That’s it?

  • Vi yes! an example: https://github.com/Initsogar/cordova-webintent/blob/master/src/android/WebIntent.java

Show 7 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.