0

Azure 푸시 알림을 처음 시도했는데, 이제 구현 후 onMessage에서 멈추게됩니다. OnMessage 수신이 실패하지 않습니다. 앱이 성공적으로 등록되었습니다. AndroidManifest 파일을 변경하지 않았으므로 코드를 업로드하고 있습니다. 아래에 몇 가지 설정 : - 패키지 이름 : - PACKAGE_NAME은(Azure) 푸시 알림의 OnMessage가 작동하지 않습니다.

[assembly: Permission(Name = "pACKAGE_NAME.permission.C2D_MESSAGE")] [assembly: UsesPermission(Name = "pACKAGE_NAME.permission.C2D_MESSAGE")] [assembly: UsesPermission(Name = "com.google.android.c2dm.permission.RECEIVE")] [assembly: UsesPermission(Name = "android.permission.GET_ACCOUNTS")] [assembly: UsesPermission(Name = "android.permission.INTERNET")] [assembly: UsesPermission(Name = "android.permission.WAKE_LOCK")] 

네임 스페이스 내가 알림 허브를 가진 자 마린 포럼 샘플 APP을 준비했습니다 {

[BroadcastReceiver(Permission = Gcm.Client.Constants.PERMISSION_GCM_INTENTS)] 
[IntentFilter(new string[] { Gcm.Client.Constants.INTENT_FROM_GCM_MESSAGE }, 
    Categories = new string[] { "pACKAGE_NAME" })] 
[IntentFilter(new string[] { Gcm.Client.Constants.INTENT_FROM_GCM_REGISTRATION_CALLBACK }, 
    Categories = new string[] { "pACKAGE_NAME" })] 
[IntentFilter(new string[] { Gcm.Client.Constants.INTENT_FROM_GCM_LIBRARY_RETRY }, 
    Categories = new string[] { "pACKAGE_NAME" })] 

public class MyBroadcastReceiver : GcmBroadcastReceiverBase<PushHandlerService> 
{ 
    public static string[] SENDER_IDS = new string[] { Constants.SenderID }; 

    public const string TAG = "MyBroadcastReceiver-GCM"; 
} 


[Service] // Must use the service tag 
public class PushHandlerService : GcmServiceBase 
{ 
    public static string RegistrationID { get; private set; } 
    private NotificationHub Hub { get; set; } 

    public PushHandlerService() : base(Constants.SenderID) 
    { 
     Log.Info(MyBroadcastReceiver.TAG, "PushHandlerService() constructor"); 
    } 

    protected override void OnRegistered(Context context, string registrationId) 
    { 
     Log.Verbose(MyBroadcastReceiver.TAG, "GCM Registered: " + registrationId); 
     RegistrationID = registrationId; 

     createNotification("PushHandlerService-GCM Registered...", 
      "The device has been Registered!"); 

     Hub = new NotificationHub(Constants.NotificationHubName, Constants.ListenConnectionString, 
      context); 
     try 
     { 
      Hub.UnregisterAll(registrationId); 
     } 
     catch (Exception ex) 
     { 
      Log.Error(MyBroadcastReceiver.TAG, ex.Message); 
     } 

     //var tags = new List<string>() { "falcons" }; // create tags if you want 
     var tags = new List<string>() { }; 

     try 
     { 
      var hubRegistration = Hub.Register(registrationId, tags.ToArray()); 
     } 
     catch (Exception ex) 
     { 
      Log.Error(MyBroadcastReceiver.TAG, ex.Message); 
     } 
    } 

    protected override void OnMessage(Context context, Intent intent) 
    { 
     Log.Info(MyBroadcastReceiver.TAG, "GCM Message Received!"); 

     var msg = new StringBuilder(); 

     if (intent != null && intent.Extras != null) 
     { 
      foreach (var key in intent.Extras.KeySet()) 
       msg.AppendLine(key + "=" + intent.Extras.Get(key).ToString()); 
     } 

     string messageText = intent.Extras.GetString("message"); 
     if (!string.IsNullOrEmpty(messageText)) 
     { 
      createNotification("New hub message!", messageText); 
     } 
     else 
     { 
      createNotification("Unknown message details", msg.ToString()); 
     } 
    } 


    void createNotification(string title, string desc) 
    { 
     //Create notification 
     var notificationManager = GetSystemService(Context.NotificationService) as NotificationManager; 

     //Create an intent to show UI 
     var uiIntent = new Intent(this, typeof(MainActivity)); 

     //Create the notification 
     var notification = new Notification(Android.Resource.Drawable.SymActionEmail, title); 

     //Auto-cancel will remove the notification once the user touches it 
     notification.Flags = NotificationFlags.AutoCancel; 

     //Set the notification info 
     //we use the pending intent, passing our ui intent over, which will get called 
     //when the notification is tapped. 
     notification.SetLatestEventInfo(this, title, desc, PendingIntent.GetActivity(this, 0, uiIntent, 0)); 

     //Show the notification 
     notificationManager.Notify(1, notification); 
     dialogNotify(title, desc); 
    } 

    protected void dialogNotify(String title, String message) 
    { 

     MainActivity.instance.RunOnUiThread(() => { 
      AlertDialog.Builder dlg = new AlertDialog.Builder(MainActivity.instance); 
      AlertDialog alert = dlg.Create(); 
      alert.SetTitle(title); 
      alert.SetButton("Ok", delegate { 
       alert.Dismiss(); 
      }); 
      alert.SetMessage(message); 
      alert.Show(); 
     }); 
    } 


    protected override void OnUnRegistered(Context context, string registrationId) 
    { 
     Log.Verbose(MyBroadcastReceiver.TAG, "GCM Unregistered: " + registrationId); 

     createNotification("GCM Unregistered...", "The device has been unregistered!"); 
    } 

    protected override bool OnRecoverableError(Context context, string errorId) 
    { 
     Log.Warn(MyBroadcastReceiver.TAG, "Recoverable Error: " + errorId); 

     return base.OnRecoverableError(context, errorId); 
    } 

    protected override void OnError(Context context, string errorId) 
    { 
     Log.Error(MyBroadcastReceiver.TAG, "GCM Error: " + errorId); 
    } 

} 

}

+0

는 모든 솔루션을 가지고있다? – sunita

답변

0

을 App1.Droid. 여기 링크 : https://1drv.ms/u/s!AuKd5Hvq8SOlo8Fukh4KcX6GtIoPmQ.

코드와 비교하여 놓친 것이 있는지 확인하십시오. 이 앱은 Xamarin.GooglePlayServices.Gcm 패키지 버전 25.0.0 (최신 버전 대신 29.0.0.2)을 사용합니다.

감사합니다,

Sateesh는

+0

고마워 ** Sateesh **, 문제가 해결되었습니다. 포트는 블록이어서 모바일 데이터를 사용했습니다. –

관련 문제