Bring Cordova Application To Foreground When Push Arrives
I have app up and running. Push notifications are working ok. I need that when push arrives, bring app to foreground, on Android. So, what I found is this piece of code: Intent toL
Solution 1:
The java compiler is telling you that it doesn't know what MainActivity.class
is while compiling GCMIntentService.java
. You must import MainActivity
class from the package where it is defined e.g. if the package is called cordovaExample
then at the top of GCMIntentService.java
put
import cordovaExample.MainActivity;
and the class must be declared public
package cordova;
publicclassMainActivity {
Solution 2:
Here is what I did, Changes on GMCIntentService.java file which worked great for me.
import com.package.app.*;
@OverrideprotectedvoidonMessage(Context context, Intent intent) {
Log.d(TAG, "onMessage - context: " + context);
// Extract the payload from the messageBundleextras= intent.getExtras();
if (extras != null)
{
// if we are in the foreground, just surface the payload, else post it to the statusbarif (PushPlugin.isInForeground()) {
extras.putBoolean("foreground", true);
PushPlugin.sendExtras(extras);
}
else {
extras.putBoolean("foreground", false);
Log.d(TAG, "force launch event");
Intentwintent=newIntent(context, MainActivity.class);
wintent.addFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(wintent);
// Send a notification if there is a messageif (extras.getString("message") != null && extras.getString("message").length() != 0) {
createNotification(context, extras);
PushPlugin.sendExtras(extras);
}
}
}
}
Post a Comment for "Bring Cordova Application To Foreground When Push Arrives"