【发布时间】:2016-09-04 23:44:27
【问题描述】:
我正在尝试为以下要求创建一个简洁的解决方案:
a) 当用户“点击”我的应用收到的通知并且该应用已打开和/或在后台运行时,该应用将使用该字体。
b) 当用户“点击”通知并关闭应用程序时,会显示启动画面并且应用程序会正常启动。
我正在尝试,但我只在上述任一选项中都取得了成功,可悲的是,两者都没有。这是我的代码:
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);
}
为简单起见,我有两个活动:
public class SplashScreen : MvxSplashScreenActivity
和
public class DashboardView : BaseMvxActivity
如果我使用“SplashScreen”作为通知的 PendingIntent,并且应用程序已经启动/打开/在后台,它会挂在 splashScreen 上。 MvvmCross 日志显示“显示 ViewModel DashboardViewModel”,但停在那里。不调用 OnCreate、Init 和 Start。飞溅只是停留。
如果我使用“DashboardView”作为通知的 PendingIntent 并且应用程序已关闭/未激活,那么我只会在启动时看到白屏并且没有启动屏幕。
我想要两全其美:)。因此,当点击推送消息并打开应用程序时,只需将应用程序放在前面(如果还没有的话)。当应用程序关闭时,显示启动画面等。
我希望我已经把我的问题说清楚了。
非常感谢。
【问题讨论】:
-
你管理过这个吗?我被困在同样的行为上。
-
即使我也面临同样的问题..