【发布时间】:2018-08-24 00:10:18
【问题描述】:
我按照那里的解析教程进行操作: http://docs.parseplatform.org/dotnet/guide/#push-on-xamarin-android
但我没有收到任何推送通知
那里有关于Android配置的部分:http://docs.parseplatform.org/tutorials/android-push-notifications/
但我真的不明白“为推送通知注册设备”部分之后发生了什么,因为在 Xamarin.forms 中,我没有 Application.cs
我尝试将此代码放入 App.cs 文件,但我无法覆盖 OnCreate 方法(如教程中所述) 它在 App.cs 的 init 中不起作用
然后,我尝试在我的 Android 项目中创建一个名为“ParseApplication”的新类:
using System;
using Android.App;
using Android.Runtime;
using Parse;
namespace MyApp.Droid
{
[Application(Name = "fr.MyCompany.MyApp.ParseApplication")]
class ParseApplication : Application
{
public ParseApplication(IntPtr handle, JniHandleOwnership ownerShip)
: base(handle, ownerShip)
{
}
public override void OnCreate()
{
base.OnCreate();
ParseClient.Initialize(new ParseClient.Configuration
{
ApplicationId = Constants.ParseApplicationId,
WindowsKey = Constants.ParseWindowsKey,
Server = Constants.ParseServer
});
ParsePush.ParsePushNotificationReceived += ParsePush.DefaultParsePushNotificationReceivedHandler;
ParseInstallation.CurrentInstallation.SaveAsync();
}
}
}
这是我的 AndroidManifest.xml :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionName="1.0.5"
package="fr.MyCompany.MyApp" android:installLocation="auto" android:versionCode="6">
<uses-sdk android:minSdkVersion="19" android:targetSdkVersion="27" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<application android:label="MyApp" android:icon="@drawable/logo">
<service android:name="com.parse.PushService" />
<receiver android:name="com.parse.ParsePushBroadcastReceiver"
android:exported="false">
<intent-filter>
<action android:name="com.parse.push.intent.RECEIVE" />
<action android:name="com.parse.push.intent.DELETE" />
<action android:name="com.parse.push.intent.OPEN" />
</intent-filter>
</receiver>
<receiver android:name="com.parse.GcmBroadcastReceiver"
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" />
<!--
IMPORTANT: Change "com.parse.starter" to match your app's package name.
-->
<category android:name="fr.MyCompany.MyApp" />
</intent-filter>
</receiver>
<!--
IMPORTANT: Change "YOUR_SENDER_ID" to your GCM Sender Id.
-->
<meta-data android:name="com.parse.push.gcm_sender_id"
android:value="id:XXXXXXXXXXXX" />;
</application>
</manifest>
它没有工作......
看看我的推:
我指定我没有 Android 手机,然后我可以尝试 Android Emulator (API 26)。我希望这不是问题
我正在使用由 Sashido 托管的解析
谢谢
编辑
我刚刚看到“ParseInstallation.CurrentInstallation.SaveAsync();”这行没有保存 deviceToken:
【问题讨论】:
标签: xamarin parse-platform push-notification xamarin.forms xamarin.android