在库项目下面的Andr​​oid 4 GCM问题 [英] GCM issues below Android 4 in a library Project

查看:110
本文介绍了在库项目下面的Andr​​oid 4 GCM问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我对较低Android版本上运行的设备GCM这真的奇怪的问题。我已经启用了GCM一个Android库项目。我出口它作为一个罐子,然后将其包含在测试应用程序。它正常工作与设备和仿真器API级别17和设备获得成功注册,但它不低于工作。现在这里是怪异的一部分:如果我运行库项目作为一个单独的项目,它工作正常上包括API级别10.所有的设备没有任何一个有可能是什么原因什么想法?

So, I have this really weird issue with GCM on devices running on lower versions of android. I have an android library project with GCM enabled. I export it as a jar and then include it in a test application. It works fine with devices and emulator for api level 17 and devices get registered successfully but it doesn't work below that. Now here is the weird part: If i run the library project as a standalone project, it works fine on all devices including api level 10. Does any one has any idea of what could be the reason ?

请注意:使用库是非常重要的,我

Note: Using a library is important for me.

编辑:结果
这是我在我的日志猫得到:


This is what i get in my log cat:

    D/GCMRegistrar(505): resetting backoff for com.example.gcmtest
    V/GCMRegistrar(505): Registering app com.example.gcmtest of senders 378013620721

和没有进一步的回应。

推荐答案

好吧,我理解了它自己。万一别人面临的未来这一问题;结果
我会尽力说明什么问题了。结果
于是,我只好用GCM集成库项目说的 com.test.gcm库。我想使用这个库在另一个应用程序项目说的 com.example.gcmtest 。按照这里接受的答案 我设法在成功使用library我 com.example.gcmtest 项目。它的工作罚款API级别17,但是当我用API级别10试了一下,没有的GCMIntenetService方法将会被调用,当我在我的问题贴,但我设法最终解决这个问题,就可以产生没有任何反应。诀窍是改变的意图类别接收器清单文件。要precise,我的清单文件中更改接收声明 com.example.gcmtest 此:

Ok i figured it out myself. Just in case someone else faces this issue in future;
i'll try to explain what the issue was.
So i had a library project with GCM integration say com.test.gcm-library. I wanted to use this library in another application project say com.example.gcmtest. By following the accepted answer here i managed to to use the library successfully in my com.example.gcmtest project. It worked fine with API level 17 but when i tried it with api level 10, none of the GCMIntenetService methods would get called and no response would be generated as i posted in my question but i managed to fix it finally. The trick was to change the intent category for receiver in the manifest file. To be precise, i changed the receiver declaration in the manifest file of com.example.gcmtest from this:

    <receiver
        android:name="com.test.gcm-library.MyCustomBroadcastReceiver"
        android:permission="com.google.android.c2dm.permission.SEND" >
        <intent-filter>

            <!-- Receives the actual messages. -->
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            <!-- Receives the registration id. -->
            <action android:name="com.google.android.c2dm.intent.REGISTRATION" />

            <category android:name="com.test.gcm-library" />
        </intent-filter>
    </receiver>  

这样:

    <receiver
        android:name="com.test.gcm-library.MyCustomBroadcastReceiver"
        android:permission="com.google.android.c2dm.permission.SEND" >
        <intent-filter>

            <!-- Receives the actual messages. -->
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            <!-- Receives the registration id. -->
            <action android:name="com.google.android.c2dm.intent.REGISTRATION" />

            <category android:name="com.example.gcmtest" />
        </intent-filter>
    </receiver>

我不知道为什么,但接收方类别字段看起来像API 17一个不关心状态,但较低的API这是我不得不这样做,使其工作。

I don't know why but the receiver category field looked like a "dont care" condition for API 17 but for lower APIs this is what i had to do to make it work.

这篇关于在库项目下面的Andr​​oid 4 GCM问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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