나는 xamarin을 통해 만들어진 안드로이드 응용 프로그램에서 A 버튼을 클릭하면 GCM 알림을 보내야합니다.버튼에 원격 알림을 보내는 방법을 클릭하십시오. Xamarin.Android C#
Button btnCLick = Findviewbyid<button>(resource.id.btnclikc);
btnCLick.Click += btnCLick_CLICK;
void btnCLick_Click (object sender, System.EventArgs e)
{
// Here i need to send my notification. I am not able to get it.
}
내 통지를 보내도록 MessageSender.exe를 사용하지만 난 내 응용 프로그램으로 만들 기운을 따랐다.
using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;
namespace MessageSender
{
class Program
{
public const string API_KEY = "API_KEY";
public const string MESSAGE = "MESSAGE";
static void Main(string[] args)
{
var jGcmData = new JObject();
var jData = new JObject();
jData.Add("message", MESSAGE);
jGcmData.Add("to", "/topics/global");
jGcmData.Add("data", jData);
var url = new Uri("https://gcm-http.googleapis.com/gcm/send");
try
{
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Accept.Add(
new MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.TryAddWithoutValidation(
"Authorization", "key=" + API_KEY);
Task.WaitAll(client.PostAsync(url,
new StringContent(jGcmData.ToString(), Encoding.Default, "application/json"))
.ContinueWith(response =>
{
Console.WriteLine(response);
Console.WriteLine("Message sent: check the client device notification tray.");
}));
}
}
catch (Exception e)
{
Console.WriteLine("Unable to send GCM message:");
Console.Error.WriteLine(e.StackTrace);
}
}
}
}
나는 내가 그렇게하는 방법을 xamarin.Android 에 내 응용 프로그램의 버튼 클릭으로 이것을 할 필요가?
당신의 안드로이드 애플 리케이션에서 메시지를 보내려고입니까? –
예 푸시 알림 –
클라이언트 응용 프로그램이 글로벌 주제에 가입 했습니까? 질문에 해당 코드를 포함시킬 수 있습니까? –