繁体   English   中英

推送通知已收到,但未收到任何消息

[英]Push Notification received, but no message

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

推送通知已收到,但没有消息,仅当我单击通知中的启动器应用程序启动器图标时,却未收到消息。

我在这里仅处理接收通知部分,该通知是由服务器上的其他人发送的,他为此使用VB.net,无法检查其代码。 但是我可以发布我的。 我的onMessage:

protected void onMessage(Context context, Intent intent) {


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


  generateNotification(context, message);

}

我的generateNotification

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代码发送消息,请帮忙,我也可以提供。

谢谢,阿斯米

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM