Android 推送通知,未授予权限

Android push notifications, not granting permission

我正在尝试使用 this package

在我的 android 应用程序(内置 react-native)上启用通知

这是我的 MANIFEST.XML 文件的一部分:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
 package="{package_name}"
 android:versionCode="1"
 android:versionName="1.0.0"
 android:minSdkVersion="21"
 android:targetSdkVersion="23">

<permission
    android:name="com.xxx.permission.C2D_MESSAGE"
    android:protectionLevel="signature" />

<uses-permission android:name="com.xxx.permission.C2D_MESSAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="com.google.android.c2dm.permission.SEND" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.GET_TASKS" /> 

...

<receiver
  android:name="com.google.android.gms.gcm.GcmReceiver"
  android:exported="true"
  android:permission="com.google.android.c2dm.permission.SEND" >
  <intent-filter>
    <action android:name="com.google.android.c2dm.intent.RECEIVE" />
    <category android:name="com.xxx" />
  </intent-filter>
</receiver>
<service android:name="com.oney.gcm.GcmRegistrationService"/>
<service android:name="com.oney.gcm.BackgroundService"></service>

<service
  android:name="com.oney.gcm.RNGcmListenerService"
  android:exported="false" >
  <intent-filter>
    <action android:name="com.google.android.c2dm.intent.RECEIVE" />
  </intent-filter>
</service>
<receiver
  android:exported="false"
  android:name="com.oney.gcm.GcmBroadcastReceiver">
  <intent-filter>
    <action android:name="com.oney.gcm.GCMReceiveNotification" />
    </intent-filter>
</receiver>

<receiver android:name="io.neson.react.notification.NotificationEventReceiver" />
<receiver android:name="io.neson.react.notification.NotificationPublisher" />
<receiver android:name="io.neson.react.notification.SystemBootEventReceiver">
  <intent-filter>
    <action android:name="android.intent.action.BOOT_COMPLETED"></action>
  </intent-filter>
</receiver>

不幸的是,当我安装我的应用程序时,我的日志中有这个:

W/PackageManager( 873): Not granting permission com.google.android.c2dm.permission.SEND to package (protectionLevel=18 flags=0x8be46)

对这个问题有什么想法吗?

谢谢。

您的项目存在 C2DM 设置问题 level.Either 逐步完成 official doc or follow this tutorial

更改 Manifest.xml

时要执行的步骤
  • 接收 C2DM 消息的权限
  • 访问互联网
  • 限制对您的 C2DM 消息的访问,以免其他应用看到它们
  • 声明一个接收器,我们稍后会创建它,让我们接收 C2DM 事件
  • 确保设置了 minSdkVersion,以便只有 2.2 及更高版本可以访问您的应用程序

我认为是因为您使用的是已弃用的 api

Important: C2DM was officially deprecated on June 26, 2012, and will be shut down completely as of October 20, 2015. Existing C2DM developers are encouraged to migrate to Google Cloud Messaging (GCM). See the C2DM-to-GCM Migration document for more information. Developers must use GCM for new development.

https://developers.google.com/android/c2dm/?csw=1#manifest