C# 单击按钮时Xamarin表单本地通知不显示
我是Xamarin表单的新手,我试图在单击按钮时显示本地通知 我已经安装了这个插件: - - 问题是,这个插件不起作用。我已经走了每一步,但我不明白为什么我仍然一无所有 这里是我的XAML:C# 单击按钮时Xamarin表单本地通知不显示,c#,xamarin.forms,C#,Xamarin.forms,我是Xamarin表单的新手,我试图在单击按钮时显示本地通知 我已经安装了这个插件: - - 问题是,这个插件不起作用。我已经走了每一步,但我不明白为什么我仍然一无所有 这里是我的XAML: <?xml version="1.0" encoding="utf-8" ?> <ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="LeafWords.Classes.SettingsLeaf.WordSettings">
<ContentPage.Content>
<StackLayout>
<Button Clicked="WordNotif" Text="Local Notification"></Button>
</StackLayout>
</ContentPage.Content>
</ContentPage>
我已经检查了LocalNotifications Github页面的设置部分,那里的代码本身无法工作,您需要将SET_ALARM权限添加到Android清单中 将以下内容添加到AndroidManifest.xml文件中:
<uses-permission android:name="android.permission.ACCESS_NOTIFICATION_POLICY"/>
<uses-permission android:name="com.android.alarm.permission.SET_ALARM" />
以下是最终版本的外观:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="auto">
<uses-sdk android:minSdkVersion="15" />
<uses-permission android:name="android.permission.ACCESS_NOTIFICATION_POLICY" />
<uses-permission android:name="com.android.alarm.permission.SET_ALARM" />
<application android:label="Notification.Android">
<receiver android:name="localnotifications.plugin.ScheduledAlarmHandler" android:enabled="true"></receiver>
</application>
</manifest>
我找到了这个链接,它正在工作:
可能与@GeraldVersluis重复主题不同我看不到您尝试单击按钮,我在构造函数中看到它。你等10秒钟吗?你在哪个平台上测试?如果是Android,你添加了@YuriS吗?我在Android上测试了谢谢,我试过了,但仍然不起作用,请给我看一下你的类。Hi@hugo,你确认了WordNotif函数被调用了吗?你能把它改成“void WordNotif(object sender,EventArgs e){….}”吗?void WordNotif(object sender,EventArgs e){//当你的应用程序启动var notification=new LocalNotification{Text=“Hello Plugin”,Title=“Nbation Plugin”时处理,Id=2,NotifyTime=DateTime.Now};var notifier=CrossLocalNotifications.CreateLocalNotifier();notifier.Notify(notification);}将代码推送到github并添加到答案的链接。推送到git的文件看起来都很好,我需要让项目在我这边运行,看看为什么它不工作,如果你不想共享更多的代码,你能创建你的项目的较小版本,并将其推到git,这样我就可以运行它吗?
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="auto">
<uses-sdk android:minSdkVersion="15" />
<uses-permission android:name="android.permission.ACCESS_NOTIFICATION_POLICY" />
<uses-permission android:name="com.android.alarm.permission.SET_ALARM" />
<application android:label="Notification.Android">
<receiver android:name="localnotifications.plugin.ScheduledAlarmHandler" android:enabled="true"></receiver>
</application>
</manifest>