【问题标题】:Push Notification Onclick it should open the application推送通知 Onclick 它应该打开应用程序
【发布时间】:2015-04-29 22:55:14
【问题描述】:

我正在开发一个应用程序并使用推送通知。我的应用程序包含一个 ID 列表。点击特定的 id,我可以看到与该 id 相关的详细信息。

推送通知包含一个 id,所以我希望如果我点击推送通知,它将打开 id 的详细信息页面,以显示与通知中的 id 相关的详细信息。

例如 在我的应用程序中,我有多个 ID(例如 123,456,657...),如果我点击 123,它将显示与 ID 相关的详细信息,例如姓名、电话号码、电子邮件等。我的推送通知包含 123,我希望如果我点击推送通知,它将打开 123 id 的详细信息页面。

【问题讨论】:

  • 不清楚..请解释更多..
  • 在我的应用程序中,我有多个 ID(例如 123,456,657...),通过单击 123,它将显示 ID 的详细信息,例如姓名、电话号码、电子邮件等。以及我的推送通知包含 123,我想点击推送通知它将打开 123 id 的详细信息页面。
  • 所以你必须通过Bundle 传递你的 id 并在你的活动中获取它并检查它是否包含该 id。如果是,则显示具有该 ID 的特定通知详细信息的详细信息。

标签: android push-notification


【解决方案1】:

您必须将id 作为与通知相关联的额外意图:

NotificationCompat.Builder builder = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.ic_launcher)
            .setAutoCancel(true);

// Create intent and set extra
Intent targetIntent = new Intent(this, <YourDetailsActivity>.class);
targetIntent.putExtra("id", id);

// Associate intent to notification
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, targetIntent, PendingIntent.FLAG_UPDATE_CURRENT);
builder.setContentIntent(contentIntent);

// Create notification...
Notification notification = builder.build();

// ...and show it
NotificationManager nManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
nManager.notify(<YOUR_NOTIFICATION_ID>, notification);

【讨论】:

    【解决方案2】:

    使用 PushNotification 您正在为应用程序的本地数据库中的项目或 WebService 调用 id 或其他任何东西传递一些 id。

    为该 DetailActivity 创建一个挂起的 Intent 并在 bundle 中为此传递这个 id.. 并在此处从 bundle 中将代码写入 getId 并基于从数据库或 WebService 获取数据..

    如果有任何疑问,请随时询问..

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-13
      • 1970-01-01
      相关资源
      最近更新 更多