2015-11-05 71 views
0

我正在使用GCM在Android中接收推送通知。下面我有在Android中的主要活動,代碼依賴於Xamarin.Forms項目沒有收件人允許在Gcm.Client.GcmClient.CheckManifest處接收com.google.android.c2dm.permission.SEND - Xamarin.Forms

try 
      { 
       //Check to see that GCM is supported and that the manifest has the correct information 
       GcmClient.CheckDevice(this); 
       GcmClient.CheckManifest(this); 

       var registrationId = GcmClient.GetRegistrationId(this); 
       if (string.IsNullOrEmpty(registrationId)) 
       { 
        GcmClient.Register(this, GcmBroadcastReceiver.SENDER_IDS); 
       } 
      } 
      catch (Exception e) 
      { 

      } 

在執行檢查的異常表現低於其投擲:

No receiver allowed to receive com.google.android.c2dm.permission.SEND 
    at Gcm.Client.GcmClient.CheckManifest 

但我已經在明顯增加必要的權限,下面是我的清單:

<uses-sdk android:targetSdkVersion="21" /> 
    <uses-permission android:name="android.permission.INTERNET" /> 
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> 
    <uses-permission android:name="android.permission.WAKE_LOCK" /> 
    <uses-permission android:name="android.permission.GET_ACCOUNTS" /> 
    <uses-permission android:name="android.permission.READ_PHONE_STATE" /> 
    <permission android:name="com.package.name.permission.C2D_MESSAGE" android:protectionLevel="signature" /> 
    <uses-permission android:name="com.package.name.permission.C2D_MESSAGE" /> 
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" /> 
    <application android:label="Mobile.Droid" android:icon="@drawable/icon" android:theme="@android:style/Theme.Holo.Light"></application> 

我有我的Xamarin.Android項目,其中與GCM註冊成功,爲什麼在這裏它扔excep的同一個清單文件重刑?

我錯過了什麼?

回答

0

我認爲錯誤是因爲你沒有設置的權限:

com.google.android.c2dm.permission.SEND

嘗試設置權限在您的自定義廣播接收器類是這樣的:

[BroadcastReceiver(Permission = "com.google.android.c2dm.permission.SEND")] 
[IntentFilter(new string[] { "com.google.android.c2dm.intent.RECEIVE" }, Categories = new string[] { "@[email protected]" })] 
[IntentFilter(new string[] { "com.google.android.c2dm.intent.REGISTRATION" }, Categories = new string[] { "@[email protected]" })] 
[IntentFilter(new string[] { "com.google.android.gcm.intent.RETRY" }, Categories = new string[] { "@[email protected]" })] 
public class MyGCMBroadcastReceiver : BroadcastReceiver 
{ 
    const string TAG = "PushHandlerBroadcastReceiver"; 
    public override void OnReceive(Context context, Intent intent) 
    { 
     MyIntentService.RunIntentInService(context, intent); 
     SetResult(Result.Ok, null, null); 
    } 
} 

我希望它能幫助