简体   繁体   English

如何实现xamarin android的推送通知

[英]How to implement push notification for xamarin android

I tried to follow the tutorial: Push notifications to Xamarin.Android (the iOS part works already) 我尝试按照教程:将通知推送到Xamarin.Android (iOS部分已经工作)

But I get the following error at build time: 但是我在构建时遇到以下错误:

The "ProcessGoogleServicesJson" task was not given a value for the required parameter "ResStringsPath". “ProcessGoogleServicesJson”任务未获得所需参数“ResStringsPath”的值。 ServiceToolStandard.Android ServiceToolStandard.Android

What I have so far: 到目前为止我所拥有的:

  • I've created a firebase project 我创建了一个firebase项目
  • FirebaseConsole: FirebaseConsole:
    • downloaded the google-services.json file 下载了google-services.json文件
    • copied the legacy server key 复制旧服务器密钥
  • Azure: Azure的:
    • created notification hub 创建了通知中心
    • inserted the legacy server key 插入旧服务器密钥
  • Xamarin Forms App (Android): Xamarin Forms App(Android):
    • AndroidManifest package name == package name firebase project AndroidManifest包名==包名firebase项目
    • I installed the nuget packages: Xamarin.GooglePlayServices.Base, Xamarin.Firebase.Messaging and Xamarin.Azure.NotificationHubs.Android 我安装了nuget软件包:Xamarin.GooglePlayServices.Base,Xamarin.Firebase.Messaging和Xamarin.Azure.NotificationHubs.Android
    • added the google-services.json file to the project and selected the Build Action to GoogleServiceJson 将google-services.json文件添加到项目中,并选择Build Action to GoogleServiceJson
    • added the receiver part to the AndroidManifest* 接收器部分添加到AndroidManifest *
    • Then created the classes Constants, MyFirebaseIIDService, MyFirebaseMessagingService and edited the MainActivity 然后创建了类Constants,MyFirebaseIIDService,MyFirebaseMessagingService并编辑了MainActivity

after that the tutorial says "build your project / run your app..." and I get the error. 之后,教程说“构建你的项目/运行你的应用程序...”,我得到了错误。

*here I'm not quite sure what to fill in at ${applicationId}: *这里我不太确定要在$ {applicationId}填写什么:

<receiver android:name="com.google.firebase.iid.FirebaseInstanceIdInternalReceiver" android:exported="false" />
  <receiver android:name="com.google.firebase.iid.FirebaseInstanceIdReceiver" android:exported="true" android:permission="com.google.android.c2dm.permission.SEND">
  <intent-filter>
    <action android:name="com.google.android.c2dm.intent.RECEIVE" />
    <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
    <category android:name="${applicationId}" />
  </intent-filter>
</receiver>

Thanks for your help! 谢谢你的帮助!

So I'm not quite sure why I got that error. 所以我不太清楚为什么会出现这个错误。 But after updating visual studio from v15.7.1 to v15.7.2 the error was gone. 但在将Visual Studio从v15.7.1更新到v15.7.2后,错误消失了。 It could be, that a restart of visual studio was the solution? 可能是,重新启动visual studio是解决方案吗? In the tutorial it say's you have to restart vs if you can't select the Build Action "GoogleServiceJson". 在教程中它说如果你不能选择Build Action“GoogleServiceJson”,你必须重新启动vs。 Perhaps you have to restart it anyway. 也许你必须重新启动它。

For android:name="${applicationId}" I used the same as in "package" out of the "manifest" line in the AndroidManifest. 对于android:name =“$ {applicationId}”我在AndroidManifest中的“manifest”行中使用了与“package”相同的内容。

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="3" android:versionName="1.2" package="com.xxxxx.ServiceToolStandard" android:installLocation="auto">
[...]
<application android:label="ServiceToolStandard" android:icon="@drawable/icon">
    <receiver android:name="com.google.firebase.iid.FirebaseInstanceIdInternalReceiver" android:exported="false" />
    <receiver android:name="com.google.firebase.iid.FirebaseInstanceIdReceiver" android:exported="true" android:permission="com.google.android.c2dm.permission.SEND">
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
            <category android:name="com.xxxxx.ServiceToolStandard" />
        </intent-filter>
    </receiver>
</application>

Now I can build and run the application. 现在我可以构建并运行应用程序了。 Also the push notifications from the Azure-"Test send" are received correctly. 此外,Azure - “测试发送”的推送通知也会正确接收。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM