gpt4 book ai didi

c# - Xamarin Google Cloud Messaging GcmClient.CheckDevice(this) 导致运行时错误

转载 作者:行者123 更新时间:2023-11-29 20:43:14 25 4
gpt4 key购买 nike

因此,我尝试使用 Xamarin 中的 Google Cloud Messaging Client 组件向 GCM 注册我的应用程序。

然而,当我在我的应用程序中运行此代码时,它会在 GcmClient.CheckDevice(this) 方法调用时出现运行时错误。该按钮位于主要 Activity 中,因此我可以控制何时开始注册过程。

我正在使用 Xamarin 播放器模拟器加载应用程序。

button.Click += (object sender, EventArgs e) => 
{
GcmClient.CheckDevice(this);
GcmClient.CheckManifest(this);

var preferences = GetSharedPreferences("AppData", FileCreationMode.Private);
var deviceid = preferences.GetString("DeviceId", "");
if (string.IsNullOrEmpty(deviceid))
{
Toast.MakeText(this, "I'm here", ToastLength.Short).Show();
GcmClient.Register(this, GcmBroadcastReceiver.SENDER_IDS);
}

};

如有任何帮助,我们将不胜感激。这是我的 list

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="my_package_name">
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="21" />
<application android:label="patientFlowNotifications"></application>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.VIBRATE" />
</manifest>

最佳答案

默认情况下,Xamarin Player Emulator 不随 Google Play 服务一起提供。您需要手动安装它们才能使用 GCM:

http://developer.xamarin.com/guides/android/getting_started/installation/android-player/

The Google Apps and Google Play Services have been packaged by independent developers in the Android community into a flashable zip format. It is possible to install Google Apps and Google Play Services on the Xamarin Android Player yourself by following these steps:

Download the package from the internet. There are many sources for this, one possible source is the CyanogenMod web site. Start up the Android Player and unlock it. Drag and drop the zip file that you downloaded onto the Android Player. Restart the Android Player.

另一点不会不可避免地导致异常但会阻止您的应用程序按预期运行的是您没有在 list 中声明任何 Intent 过滤器并且缺少特定于应用程序的 CDM-Permission。

<permission android:name="your.package.name.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="your.package.name.permission.C2D_MESSAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />

关于c# - Xamarin Google Cloud Messaging GcmClient.CheckDevice(this) 导致运行时错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30712140/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com