【问题标题】:Xamarin Forms: Android: Toast Notifications ClickedXamarin Forms:Android:点击了 Toast 通知
【发布时间】:2017-12-20 13:21:12
【问题描述】:

我使用的是最新版本的 Xamarin Forms。我有一个内容页面。内容页面有一个包含按钮的内容。该按钮具有 Button_Clicked 事件,您可以在下面看到。我使用 IToastNitificator (https://github.com/EgorBo/Toasts.Forms.Plugin),我在关闭我的应用程序后发送此通知时尝试通过,并且在我单击通知后我的应用程序不会再次弹出。任何人都可以帮助我如何做到这一点?

这是我的 Button_Clicked 方法:

private async void Button_Clicked(object sender, EventArgs e)
    {
        var notificator = DependencyService.Get<IToastNotificator>();
        var options = new NotificationOptions()
        {
            Title = "Teszt",
            Description = "Önnek teszteket kell kitöltenie!",
            IsClickable = true
        };
        var result = await notificator.Notify(options);
        if(result.Action == NotificationAction.Clicked)
        {
            await Navigation.PushAsync(new QuestionPage());
        }
    }

我注册了这个依赖,它工作正常。

public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
    protected override void OnCreate (Bundle bundle)
    {
        TabLayoutResource = Resource.Layout.Tabbar;
        ToolbarResource = Resource.Layout.Toolbar; 

        base.OnCreate (bundle);

        Xamarin.Forms.DependencyService.Register<ToastNotification>();
        Xamarin.Forms.DependencyService.Register<OpenAppAndroid>();

        ToastNotification.Init(this);
        BluetoothLowEnergyAdapter.Init(this);
        global::Xamarin.Forms.Forms.Init (this, bundle);
        LoadApplication (new Spirocco.App (BluetoothLowEnergyAdapter.ObtainDefaultAdapter(ApplicationContext)));
    }
}

【问题讨论】:

  • 我使用这个 NuGet 包:github.com/EgorBo/Toasts.Forms.Plugin
  • 是的,我更新了我的问题,你可以看到 MainActivity
  • 这对我没有帮助:(
  • 是的,我使用相同的顺序。
  • 当我点击我的通知时,我很快想将我的应用程序备份到前台。

标签: c# xamarin xamarin.forms xamarin.android


【解决方案1】:

要重新打开 Android 应用程序,您需要在 AndroidOptions 中将 ForceOpenAppOnNotificationTap 设置为 true

例子:

var options = new NotificationOptions()
{
    Title = "Teszt",
    Description = "Önnek teszteket kell kitöltenie!",
    IsClickable = true,
    AndroidOptions = new AndroidOptions()
    {
        ForceOpenAppOnNotificationTap = true
    }
};

【讨论】:

  • 谢谢,我要来一杯啤酒。 :D 当定时器达到某个点时,我必须这样做。你知道我怎样才能做到这一点,而不是点击?
  • ? 是的,请;-) I have to do this when Timer is reach some point我不明白你的意思?
  • 当应用程序正在运行时,我是否必须运行一个定时器,如果定时器到达某个点,它会发送一个通知。
  • @TamásDeák 你可以写一个Android前台Service,但我会通过AlarmManager来做这件事,在未来设置一个闹钟,让它向@987654327发送一个广播@子类在您的应用程序中,并让该接收者的OnReceive 发送您的通知(并重新安排下一个需要的警报)
  • @TamásDeák 让它成为六人装和派对时间:? ? ? ? ? ?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-02-13
  • 2014-01-08
  • 2021-04-09
  • 1970-01-01
相关资源
最近更新 更多