0

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ボックスを試しましたが、通知を受け取った後、アプリケーションが停止します。

4

1 に答える 1