【问题标题】:How to implement push notification for xamarin android如何为 xamarin android 实现推送通知
【发布时间】:2018-11-01 06:34:09
【问题描述】:

我尝试按照教程进行操作:Push notifications to Xamarin.Android (iOS 部分已经可以使用了)

但我在构建时收到以下错误:

“ProcessGoogleServicesJson”任务没有为所需参数“ResStringsPath”指定值。 ServiceToolStandard.Android

我目前所拥有的:

  • 我创建了一个 firebase 项目
  • Firebase 控制台:
    • 下载了 google-services.json 文件
    • 复制了旧服务器密钥
  • 天蓝色:
    • 已创建通知中心
    • 已插入旧版服务器密钥
  • Xamarin 表单应用程序 (Android):
    • AndroidManifest 包名 == 包名 firebase 项目
    • 我安装了 nuget 包:Xamarin.GooglePlayServices.Base、Xamarin.Firebase.Messaging 和 Xamarin.Azure.NotificationHubs.Android
    • 将 google-services.json 文件添加到项目中并选择 Build Action to GoogleServiceJson
    • receiver 部分添加到 AndroidManifest*
    • 然后创建类 Constants、MyFirebaseIIDService、MyFirebaseMessagingService 并编辑 MainActivity

之后教程说“构建你的项目/运行你的应用程序......”我得到了错误。

*这里我不太确定在 ${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>

感谢您的帮助!

【问题讨论】:

    标签: android firebase xamarin push-notification firebase-cloud-messaging


    【解决方案1】:

    所以我不太清楚为什么会出现这个错误。但是在将 Visual Studio 从 v15.7.1 更新到 v15.7.2 之后,错误就消失了。可能是,重新启动视觉工作室是解决方案?在教程中,如果您无法选择构建操作“GoogleServiceJson”,则必须重新启动。也许你无论如何都必须重新启动它。

    对于 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>
    

    现在我可以构建和运行应用程序了。此外,来自 Azure-“测试发送”的推送通知也被正确接收。

    【讨论】:

    • 您可以将 ${applicationId} 留在您的 AndroidManifest 文件中,无需更改它,它会在构建时自动转换。
    猜你喜欢
    • 2020-07-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多