与不断变化的摇篮包名GCM时不登记 [英] GCM not registering when changing package name with Gradle

查看:159
本文介绍了与不断变化的摇篮包名GCM时不登记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的正常建设GCM工作正常,但是当我使用的口味改变COM域名的事情停止工作。我IntentService永远不会被初始化。我应该如何设置我的清单文件,使这种情况发生?


  • 我将它们添加到开发者控制台。

  • 我使用gradle这个com.android.tools.build:gradle:0.11 +

我得到的日志

  V / GCMBroadcastReceiver:的onReceive:com.google.android.c2dm.intent.REGISTRATION
V / GCMBroadcastReceiver:GCM IntentService类:com.sample.app.dev.GCMIntentService
V / GCMBaseIntentService:获取激活锁定

然后就没有。我的自定义IntentService类永远不会被初始化和我的registrationId保持为空。我目前的实现是一个类似于此: http://stackoverflow.com/a/20334397/198034

我应该

如何设置我的表现得到0.11的gradle +香精与GCM合作?

下面是我的风格中的一种体现,我在主清单(所有需要的权限等)更code,但没有别的处理GCM。

 <?XML版本=1.0编码=UTF-8&GT?;
<清单的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    包=com.sample.app
    安卓版code =45
    机器人:=的versionName0.6.5>    <使用许可权的android:NAME =com.google.android.c2dm.permission.RECEIVE/>
    <允许机器人:名字=com.sample.app.permission.C2D_MESSAGE
        安卓的ProtectionLevel =签名/>
    <使用许可权的android:NAME =com.sample.app.permission.C2D_MESSAGE/>    <应用
        机器人:allowBackup =真
        机器人:图标=@绘制/ app_icon
        机器人:标签=@字符串/ APP_NAME>
        <服务机器人。GCMIntentServiceNAME = />
        <接收
            机器人:名字=com.google.android.gcm.GCMBroadcastReceiver
            机器人:权限=com.google.android.c2dm.permission.SEND>
            &所述;意图滤光器>
                <作用机器人:名字=com.google.android.c2dm.intent.RECEIVE/>
                <作用机器人:名字=com.google.android.c2dm.intent.REGISTRATION/>                <类机器人:名字=$ {}的packageName/>
            &所述; /意图滤光器>
        < /接收器>
    < /用途>< /清单>


解决方案

这是我的解决方案:

 <允许机器人:名字=com.sample.app.permission.C2D_MESSAGE
     安卓的ProtectionLevel =签名/>
 <使用许可权的android:NAME =com.sample.app.permission.C2D_MESSAGE/>

...

 <服务机器人:名字=。GCMIntentService/>
    <接收
        机器人:名字=。MyBroadcastReceiver
        机器人:权限=com.google.android.c2dm.permission.SEND>
        &所述;意图滤光器>
            <作用机器人:名字=com.google.android.c2dm.intent.RECEIVE/>
            <作用机器人:名字=com.google.android.c2dm.intent.REGISTRATION/>            <类机器人:名字=com.sample.app/>
        &所述; /意图滤光器>
    < /接收器>

在我的清单和mybroadcastReceiver

...

 公共类MyBroadcastReceiver扩展GCMBroadcastReceiver
   {
    @覆盖
    保护字符串getGCMIntentServiceClassName(上下文的背景下)
    {
        返回GCMIntentService.class.getName();
    }
    }

In my regular build gcm works fine, but when I use flavors to change the com name things stop working. My IntentService is never being initialized. How should I set up my manifest files so that this happens?

  • I have added them to the developer console.
  • I am using gradle com.android.tools.build:gradle:0.11.+'

I get the logs

V/GCMBroadcastReceiver﹕ onReceive: com.google.android.c2dm.intent.REGISTRATION
V/GCMBroadcastReceiver﹕ GCM IntentService class: com.sample.app.dev.GCMIntentService
V/GCMBaseIntentService﹕ Acquiring wakelock

and then nothing. My custom IntentService class never gets initialized and my registrationId stays empty. My current implementation is similar to the one here: http://stackoverflow.com/a/20334397/198034

How should I set up my manifest to get gradle 0.11.+ flavors to work with gcm?

Below is a manifest in one of my flavors, I have more code in the main manifest (all needed permissions, etc), but nothing else dealing with gcm.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.sample.app"
    android:versionCode="45"
    android:versionName="0.6.5" >

    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />


    <permission android:name="com.sample.app.permission.C2D_MESSAGE"
        android:protectionLevel="signature" />
    <uses-permission android:name="com.sample.app.permission.C2D_MESSAGE" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/app_icon"
        android:label="@string/app_name" >


        <service android:name=".GCMIntentService" />
        <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="${packageName}" />
            </intent-filter>
        </receiver>
    </application>

</manifest>

解决方案

This was my solution:

<permission android:name="com.sample.app.permission.C2D_MESSAGE"
     android:protectionLevel="signature" />
 <uses-permission android:name="com.sample.app.permission.C2D_MESSAGE" />

...

<service android:name=".GCMIntentService" />
    <receiver
        android:name=".MyBroadcastReceiver"
        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.sample.app" />
        </intent-filter>
    </receiver>

in my manifest and mybroadcastReceiver

...

   public class MyBroadcastReceiver extends GCMBroadcastReceiver
   {
    @Override
    protected String getGCMIntentServiceClassName(Context context)
    {
        return GCMIntentService.class.getName();
    }
    }

这篇关于与不断变化的摇篮包名GCM时不登记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆