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 toPushHandlerActivity
and notMainActivity
.– Luídne
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?
– Rafael Soufraz
By your code I understood that you are sending the information in the correct way, but to the incorrect destination.
– Luídne
You’re not passing the "appUrl" to
MainActivity
therefore theMainActivity
does not receive "appUrl".– Luídne
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. :/
– Rafael Soufraz
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?
– Mateus Carvalho
The order is preserved yes. And the weather is very good. Very nice result.
– Rafael Soufraz