An alternative to the use of GCM
answered by @Gustavobitencourt, is to use Signaler for communication between Webapi and Android.
In the tutorials page of Signaler you can use the same chat example to use on android, implementing the logic of Javascript
on Android using the Signalr Client for Java/Android
You can follow these steps to take a chat test:
Deploy a Hub in your web solution
using System;
using System.Web;
using Microsoft.AspNet.SignalR;
namespace SignalRChat
{
//Nome que será utilizado para criação do hub no cliente
[HubName("chatHub")]
public class ChatHub : Hub
{
//Método utilizado para enviar a mensagem para o cliente
[HubMethodName("send")]
public void Send(string name, string message)
{
// Método que será chamado no cliente.
// Esse método precisa ser implementado no Android.
Clients.All.broadcastMessage(name, message);
}
}
}
Implement client on Android to receive messages
(in this example, the client was implemented in an Android Service)
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Logger logger = new Logger() {
@Override
public void log(String message, LogLevel level) {
Log.d("SignalR-Test", level.toString() + ":" + message);
}
};
HubConnection connection = new HubConnection(server,queryStringQualquer,true, logger);
HubProxy proxy = connection.createHubProxy("chatHub");
//Foi utilizado o tipo de transporte LongPolling, mas pode ser modificado
//pra o transport de sua preferência.
SignalRFuture<Void> awaitConnection = connection.start(new LongPollingTransport(logger));
try {
awaitConnection.get();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
proxy.on( "broadcastMessage", new SubscriptionHandler2<String, String>() {
@Override
public void run(String nome, String msg) {
//Aqui a mensagem é recebida e você exibe ela da forma que preferir
}
}, String.class, String.class);
}
Example of how to send a message to the Hub
proxy.invoke("send","Malloni","Olá, tudo bem?");
Notes
It is quite simple to implement and avoids relying on GCM for the delivery of messages, since it does not guarantee that your message will arrive on time.
You’ll have control of everything!
See if this helps: http://stackoverflow.com/questions/24359453/how-do-asp-net-backend-and-web-api-web-service-hosted-on-azure-send-push-notific?answertab=active#tab-top
– Lollipop