【问题标题】:Android push notification device to deviceAndroid 推送通知设备到设备
【发布时间】:2014-09-04 17:42:46
【问题描述】:

我想在不使用 GCM 的设备到设备的情况下进行推送通知。我想使用联系号码向任何设备发送信息。我也尝试寻找它,但找不到。我可能错了,但我必须在不使用 Google Cloud Messaging 的情况下发送推送通知设备设备,并且当在另一台设备上收到通知并打开通知时,它应该在 Activity 中打开。有人可以帮我吗。谢谢欣赏。

【问题讨论】:

  • 什么是联系电话?您是指电话号码吗?
  • @aorlando:- 是的,因为在我的应用程序中用户只需输入姓名、产品和他的联系号码,这样我就可以通过联系号码在他的设备上推送通知。

标签: java android push-notification


【解决方案1】:

要实现这个应用程序,我认为您不应该将 Android 通知与 GCM 推送通知混淆。您在 android 状态栏中看到的是 Android 通知,您可以使用 Notification Builder 类显示它:

 Notification noti = new Notification.Builder(mContext)
         .setContentTitle("New mail from " + sender.toString())
         .setContentText(subject)
         .setSmallIcon(R.drawable.new_mail)
         .setLargeIcon(aBitmap)
         .build();

所以我认为您可以使用 Android api 作为网络示例发送短信:

SmsManager smsManager = SmsManager.getDefault();
            smsManager.sendTextMessage(phoneNo, null, sms, null, null);
            Toast.makeText(getApplicationContext(), "SMS Sent!",
                        Toast.LENGTH_LONG).show();

而且你不需要使用 GCM 推送通知

要从通知中打开活动,您可以使用:

NotificationManager notifManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notif = new Notification(icon, mess, when);

Intent notifIntent = new Intent(context, Activity.class);

notifIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
        | Intent.FLAG_ACTIVITY_SINGLE_TOP);

PendingIntent intent = PendingIntent.getActivity(context, 0, notifIntent, 0);

notif.setLatestEventInfo(context, title, mess, intent);
notif.flags |= Notification.FLAG_AUTO_CANCEL;
notifManager.notify(0, notif);

【讨论】:

  • :- 感谢您的回复,但我最大的问题是当用户收到通知时,我想在 Activity 中打开。
  • 我不能在这里发布一个完整的样本,但是网络上到处都是这种东西:examples.javacodegeeks.com/android/core/ui/notifications/…
  • :- 我试过examples.javacodegeeks.com/android/core/ui/notifications/这个例子但是通知没有发送到另一个设备。即使我也改变了//创建一个隐式意图 112 Intent resultIntent = new Intent("com.example.javacodegeeks.TEL_INTENT", 113 Uri.parse("tel:123456789")); 114 resultIntent.putExtra(“来自”,“javacodegeeks”);
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2023-03-26
  • 2015-02-09
  • 1970-01-01
  • 1970-01-01
  • 2019-09-13
  • 1970-01-01
  • 2023-03-06
相关资源
最近更新 更多