我有 GCM 示例 android gradle 项目。它运行良好,当我添加 2 种口味时,推送通知停止工作。我的编译 list (取自 app\build\intermediates\manifests\ex\debug
)文件如下:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.flavor.app"
<uses-permission android:name="com.flavor.app.permission.C2D_MESSAGE" />
<permission
android:name="com.flavor.app.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<receiver
android:name="com.google.android.gcm.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" />
<category android:name="com.flavor.app" />
</intent-filter>
</receiver>
<service android:name="com.ex.app.GCMIntentService" />
<service
android:name="com.ex.app.AppLocationService"
class=".AppLocationService" >
<intent-filter>
<action
android:name=".AppLocationService"
android:value=".AppLocationService" />
</intent-filter>
</service>
我应该怎么做才能解决这个问题?请帮忙。
UPD1. 我正在使用 gradle v.0.12+。我认为我的最终 list 文件看起来不错,GCMRegistrar.checkManifest(this); - 没有错误,但 GCMRegistrar.isRegistered(this) 总是错误的。 =(
UPD2. 我的第一个具有原始包名称的 flavor 项目(作为主分支中的项目)运行良好,但具有更改包的第二个 flavor 不起作用(推送的 registrationId 仍然为空),但是在 list 文件中,所有许可都是正确的。
最佳答案
Simpy 像这样使用 ${applicationId}
别名
<permission android:name= "${applicationId}.permission.C2D_MESSAGE"
android:protectionLevel= "signature" />
<uses-permission android:name= "${applicationId}.permission.C2D_MESSAGE" />
<uses-permission android:name= "com.google.android.c2dm.permission.RECEIVE" />
对于相应的接收器使用这个
<receiver
android:name = "com.mixpanel.android.mpmetrics.GCMReceiver"
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"/>
<category android:name = "${applicationId}"/>
</intent-filter>
</receiver>
关于java - 具有产品 flavor 的 Android GCM,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25357933/