1

我正在开发一个需要接收推送通知的 android 应用程序。

收到推送通知但没有消息,就在我单击通知中的启动器图标时,它启动了应用程序,但没有收到消息。

我在这里只处理接收通知部分,通知是由其他人从服务器发送的,他正在使用 VB.net,无法检查他的代码。但我可以发布我的。我的消息:

protected void onMessage(Context context, Intent intent) {


  Log.i(TAG, "Received message");
  String message = intent.getExtras().getString("price");


  generateNotification(context, message);

}

我的生成通知

private static void generateNotification(Context context, String message) {
  int icon = R.drawable.ic_launcher;
  long when = System.currentTimeMillis();
  NotificationManager notificationManager = (NotificationManager)
          context.getSystemService(Context.NOTIFICATION_SERVICE);
  Notification notification = new Notification(icon, message, when);
  String title = context.getString(R.string.app_name);
  Intent notificationIntent = new Intent(context, CoursesMainActivity.class);
  // set intent so it does not start a new activity
  notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |
          Intent.FLAG_ACTIVITY_SINGLE_TOP);
  PendingIntent intent =
          PendingIntent.getActivity(context, 0, notificationIntent, 0);
  notification.setLatestEventInfo(context, title, message, intent);
  notification.flags |= Notification.FLAG_AUTO_CANCEL;
  // Play default notification sound

  notification.defaults |= Notification.DEFAULT_SOUND;
 // Vibrate if vibrate is enabled
  notification.defaults |= Notification.DEFAULT_VIBRATE;
  notificationManager.notify(0, notification);
  }

请对此提供帮助,如果有人想要 VB.net 代码来发送消息,我也可以提供。

谢谢,阿斯米

4

1 回答 1

0

我解决了这个问题,因为其他人(发送推送通知)没有将其作为“价格”发送,而是作为“消息”发送

于 2013-01-18T05:07:49.017 回答