c# - Xamarin 表格 : Android: Toast Notifications Clicked

标签 c# xamarin xamarin.forms xamarin.android

我使用的是最新版本的 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)));
    }
}

最佳答案

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

例子:

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

关于c# - Xamarin 表格 : Android: Toast Notifications Clicked,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47907014/

相关文章:

C#:在具有任意维度的数组中设置所有值

c# - 在 Xamarin.Forms 的 WebView 中通过 Javascript onClick 事件调用 C# 函数

c# - 从文件夹中的所有文件创建 zip 文件

c# - 文件 "obj\Debug\android\bin\packaged_resources"不存在。在 Windows 8.1 上的 Visual Studio 2015 Xamarin 跨平台中

c# - Xamarin Forms ListView 性能

c# - Xamarin.Forms 中的异步任务如何与 iOS/Android 后台模式配合使用

c# - ViewCell 中的 Xamarin.Forms 按钮。如何处理事件?

c# - 来自 odbc 阅读器 C# 的字符编码

c# - Xamarin Forms - 自定义渲染器无法获取 native 控件 (UWP)

ios - 在 Xamarin.iOS 中使用 UITableViewCell 展开 Segue