【问题标题】:Android push notifications, not granting permissionAndroid推送通知,未授予权限
【发布时间】:2016-06-03 19:49:21
【问题描述】:

我正在尝试使用 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)

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

谢谢。

【问题讨论】:

标签: android push-notification react-native


【解决方案1】:

您的项目级别存在 C2DM 设置问题。请通过official doc 或按照此tutorial 逐步操作。

更改您的Manifest.xml时要采取的步骤

  • 接收 C2DM 消息的权限
  • 访问互联网
  • 限制对您的 C2DM 消息的访问,使其他应用无法看到它们
  • 声明一个接收器,稍后我们将创建它,它将让我们接收 C2DM 事件
  • 确保已设置 minSdkVersion,以便只有 2.2 及更高版本可以访问您的应用

【讨论】:

【解决方案2】:

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

重要提示:C2DM 已于 2012 年 6 月 26 日正式弃用,并将 自 2015 年 10 月 20 日起完全关闭。现有 C2DM 鼓励开发人员迁移到 Google Cloud Messaging (GCM)。 有关更多信息,请参阅 C2DM 到 GCM 迁移文档。 开发者必须使用 GCM 进行新的开发。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-31
    • 2018-03-21
    相关资源
    最近更新 更多