1

创建推送通知的功能是

public void createNotification(Context context, Bundle extras)
{
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    String appName = getAppName(this);

    Intent notificationIntent = new Intent(this, PushHandlerActivity.class);
    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);        


    NotificationCompat.Builder mBuilder = 
        new NotificationCompat.Builder(context)
            .setSmallIcon(context.getApplicationInfo().icon)
            .setWhen(System.currentTimeMillis())
            .setContentTitle(appName)
            .setTicker(appName)
            .setContentIntent(contentIntent);

    String message = extras.getString("message");
    if (message != null) {
        mBuilder.setContentText(message);
    } else {
        mBuilder.setContentText("<missing message content>");
    }

    String msgcnt = extras.getString("msgcnt");
    if (msgcnt != null) {
        mBuilder.setNumber(Integer.parseInt(msgcnt));
    }

    mNotificationManager.notify((String) appName, NOTIFICATION_ID, mBuilder.build());
    tryPlayRingtone();
}

当我点击它时,它什么也不做。但是当点击推送通知时它必须打开我的应用程序。

项目构建目标 id Google APIs,基于 4.3 平台,API 级别 18。Androuid 支持库为 13 版本。我使用 Phonegap 和Phonegap PushPlugin

4

1 回答 1

0

问题在于 AndroidManifest.xml 中的活动。我编辑了主要活动,没有创建新的活动,就像在 github 上的文档中一样。

于 2013-08-16T09:57:26.067 回答