不同构建变体中的 Gcm c2d 权限



在像这样的不同解决方案之后,没有任何效果。

但是我正在使用不同的密钥库签署不同的口味,所以这是行不通的。

有什么线索吗?

这是我

自己的经验:

首先,使用 ${applicationId} 编辑您的主 AndroidManifest.xml,如下所示:

<permission android:name="${applicationId}.permission.C2D_MESSAGE"
    android:protectionLevel="signature" />
<uses-permission android:name="${applicationId}.permission.C2D_MESSAGE" />

由于您对不同的构建变体使用相同的 GCMIntentService 类。然后,通过覆盖创建自己的GCMBroadcastReceiver。

package com.example;
import android.content.Context;
import com.google.android.gcm.GCMBroadcastReceiver;
public class MyGCMBroadcastReceiver extends GCMBroadcastReceiver {
    @Override
    protected String getGCMIntentServiceClassName(Context context)
    {
        return "com.example.GCMIntentService";
        //you may replace with your own GCMIntentService path.
    }
}

最后,在 AndroidManifest.xml 上编辑接收者标记,如下所示:

<receiver
    android:name="com.example.MyGCMBroadcastReceiver"
    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>

我希望它对您有所帮助,谢谢。

最新更新