У меня есть приложение, в котором маркеры могут быть добавлены на карту с помощью API Карт Google. Я пытаюсь отправить уведомление всем устройствам с приложением, установленным при добавлении нового маркера, это работает для устройства, которое в настоящее время использует приложение, но не для моего другого устройства, у которого нет загруженного приложения, есть ли что-то еще, что я должен сделать, чтобы зарегистрировать его на других устройствах?Отправка уведомлений обо всех устройствах
Вот код для подключения к серверу и добавить маркер, который вызывает метод showNotification:
try
{
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost("http://***.***.***.**/markerLocation/save.php");
httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpClient.execute(httpPost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
String msg = "Data entered successfully";
//The method call that makes the alert notification
ShowNotification(name);
Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_LONG).show();
}
и вот код для создания предупреждения:
public void ShowNotification(String name)
{
// define sound URI, the sound to be played when there's a notification
Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
// intent triggered, you can add other intent for other actions
Intent intent = new Intent(GoogleMapsActivity.this, NotificationReceiver.class);
PendingIntent pIntent = PendingIntent.getActivity(GoogleMapsActivity.this, 0, intent, 0);
// this is it, we'll build the notification!
// in the addAction method, if you don't want any icon, just set the first param to 0
Notification mNotification = new Notification.Builder(this)
.setContentTitle(name)
.setContentText(name + " has added a marker in your area")
.setSmallIcon(R.drawable.ic_launcher)
.setContentIntent(pIntent)
.setSound(soundUri)
.addAction(0, "View", pIntent)
.addAction(0, "Remind", pIntent)
.build();
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
// If you want to hide the notification after it was selected, do the code below
mNotification.flags |= Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(0, mNotification);
}
Я ничего не вижу в вашем коде, что должно уведомить другие устройства? – cYrixmorten
Честно говоря, я просто последовал за учебником для добавления уведомления, подумал, что это применимо ко всем, кто использует приложение, а не только к текущему пользователю. Я предполагаю, что теперь это должно быть сделано на стороне сервера? Если бы вы могли указать мне где-то в правильном направлении, я был бы признателен за это – user2757842