单击phonegap中的gcm通知后无法打开警报/对话框

时间:2013-07-18 10:52:03

标签: android cordova google-cloud-messaging

我已在我的phonegap应用中实施了Google Cloud Messaging,但在状态栏中点击gcm通知后,我必须在对话框或提示框中显示消息。我用谷歌搜索它但无法正常工作。 GCMIntentService.java

    @Override
public void onUnregistered(Context context, String regId) {
    Log.d(TAG, "onUnregistered - regId: " + regId);
}

@Override
protected void onMessage(final Context arg0, final Intent arg1) {
    // TODO Auto-generated method stub
    Log.i("Registration", "Got a message!");
    Log.i("Registration", arg1.getStringExtra("message"));
    String message = arg1.getStringExtra("message");

    generateNotification(getApplicationContext(), message);
}

private static void generateNotification(Context context, String message) {
    long when = System.currentTimeMillis();
    NotificationManager notificationManager = (NotificationManager)
            context.getSystemService(Context.NOTIFICATION_SERVICE);
    Notification notification = new Notification(R.drawable.tbgicon, message, when);
    Intent notificationIntent = new Intent(context, KBJphoneGAP.class);
    notificationIntent.putExtra("message", message);
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |
            Intent.FLAG_ACTIVITY_SINGLE_TOP);
    String title = "The Business Game";
    PendingIntent intent =
            PendingIntent.getActivity(context, 0, notificationIntent, 0);
    notification.setLatestEventInfo(context, title, message, intent);
    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    notification.defaults|= Notification.DEFAULT_LIGHTS;
    notification.defaults|= Notification.DEFAULT_VIBRATE;
    notification.flags |= Notification.FLAG_SHOW_LIGHTS;
    notificationManager.notify(0, notification);
}

这是phonegap中的My MainActivity.java

public class MainActivity extends DroidGap {
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // Set by <content src="index.html" /> in config.xml
    // super.loadUrl(Config.getStartUrl());
    super.setIntegerProperty("splashscreen", R.drawable.splashscreen);
    super.setIntegerProperty("loadUrlTimeoutValue", 60000);
    super.loadUrl("file:///android_asset/www/index.html", 11000);
}

请有人帮我解决这个问题,我在onMessage方法中尝试过alertdialog框但是在收到通知申请后停止了。

1 个答案:

答案 0 :(得分:0)

根据您的代码:

Intent notificationIntent = new Intent(context, KBJphoneGAP.class);

点击通知即可打开KBJphoneGAP活动。 我不熟悉PhoneGap(我只知道原生的Android开发),所以我不确定那是什么活动。

如果要打开其他活动,请更改该行。