Starting app only if its not currently running

后端 未结 11 1681
我寻月下人不归
我寻月下人不归 2020-12-02 23:07

I am sending push notification to users which when clicking on it opens the app.

My problem is that when the app is already open, clicking on the notification start

11条回答
  •  离开以前
    2020-12-02 23:43

    For those who use Xamarin.Android. The Xamarin version of David Wasser's answer is below:

            //Create notification
            var notificationManager = GetSystemService(Context.NotificationService) as NotificationManager;
            Intent uiIntent = PackageManager.GetLaunchIntentForPackage("com.company.app");
    
            //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, PendingIntentFlags.OneShot));
    
            //Show the notification
            notificationManager.Notify(0, notification);
    

提交回复
热议问题