2015-11-30 42 views
5

Sto cercando di creare una soluzione semplice per l'ambiente seguente requisito:Xamarin-Android Mvvmcross - Toccando ricevuto app inizio di notifica con spruzzi o portare in primo piano

a) Quando l'utente 'rubinetti' su una notifica che la mia app riceve e l'app è aperta e/o in background, l'app verrà portata al font.

b) Quando l'utente "tocca" su una notifica e l'app è chiusa, viene visualizzata la schermata iniziale e l'app viene avviata come farebbe normalmente.

Sto provando ma ho solo successo con una delle opzioni di cui sopra, non entrambe purtroppo. Questo è il mio codice:

public void CreateNotification(string title, string desc, string pushUrl, string pushTitle) 
    { 
     var setupSingleton = MvxAndroidSetupSingleton.EnsureSingletonAvailable(ApplicationContext); 
     setupSingleton.EnsureInitialized(); 

     if (!string.IsNullOrWhiteSpace(pushUrl)) 
     { 
      var pushMessageParameterService = Mvx.Resolve<IPushMessageParameterService>(); 
      pushMessageParameterService.SetPushActionParameters(new PushActionParameters 
      { 
       UrlToShow = pushUrl, 
       ViewTitle = pushTitle 
      }); 
     } 

     var intent = new Intent(this, typeof(SplashScreen)); 
     intent.AddFlags(ActivityFlags.NewTask); 
     intent.SetAction(Intent.ActionMain); 
     intent.AddCategory(Intent.CategoryLauncher); 

     //var pendingIntent = PendingIntent.GetActivity(this, 0, intent, PendingIntentFlags.OneShot); 
     //var pendingIntent = PendingIntent.GetActivity(this, 0, intent, 0); 
     var pendingIntent = PendingIntent.GetActivity(this, 0, intent.SetFlags(ActivityFlags.BroughtToFront), PendingIntentFlags.CancelCurrent); 

     Uri alarmSound = RingtoneManager.GetDefaultUri(RingtoneType.Notification); 

     var notificationBuilder = new Notification.Builder(this) 
      .SetSmallIcon(Resource.Drawable.Icon) 
      .SetContentTitle(title) 
      .SetContentText(desc) 
      .SetAutoCancel(true) 
      .SetSound(alarmSound) 
      .SetContentIntent(pendingIntent); 

     var notificationManager = (NotificationManager)GetSystemService(Context.NotificationService); 
     Notification notification = notificationBuilder.Build(); 
     notification.Flags = NotificationFlags.ShowLights | NotificationFlags.AutoCancel; 

     notificationManager.Notify(0, notification); 
    } 

Per farla semplice, ho due attività:

public class SplashScreen : MvxSplashScreenActivity 

e

public class DashboardView : BaseMvxActivity 

Se uso il "SplashScreen" come PendingIntent per la notifica e l'app è già stata avviata/aperta/in background, si blocca su splashScreen. La registrazione di MvvmCross mostra "Mostra ViewModel DashboardViewModel" ma si ferma lì. OnCreate, Init e Start non vengono chiamati. The Splash rimane semplicemente.

Se utilizzo "DashboardView" come PendingIntent per la notifica e l'app è chiusa/non attiva, appena vedo uno schermo bianco all'avvio e nessuna schermata iniziale.

Mi piacerebbe avere il meglio di entrambi i mondi :). Quindi, quando si tocca il messaggio push e l'app è aperta, basta portare l'app in primo piano (se non lo è già). E quando l'app è chiusa, mostra lo splashscreen ecc. Ecc.

Spero di aver chiarito la mia domanda.

Molte grazie in anticipo.

+0

Hai gestito questo? Sono bloccato sullo stesso comportamento. –

+0

Anche io sto affrontando lo stesso problema .. – GvSharma

risposta

1

Quando ho provato a utilizzare MvxSplashScreenActivity per la mia intenzione, l'intenzione si bloccava su quello schermo.

Ho fatto puntare a MvxActivity standard e impostare lo sfondo da solo, insieme a NoHistory = true sull'attributo Activity. Nell'OnCreate nella mia attività in attesa, ho iniziato il vero intento.

Problemi correlati