Android C2DM 和 lib 项目
我目前正在开发一个 libproject (Android),它应该包含在其他一些应用程序中。
现在一切都工作正常,除了 C2DM 之外,我在活动和清单方面遇到了一些困难。
我可以很好地调用我的不同类,但我似乎无法捕获注册ID(或者当然是实际消息,但这一定是同一个问题......)
我认为问题来自于我的清单中的过滤( s),所以如果有人对我有任何建议,那将非常有帮助。
这是我的清单的接收器部分的副本(来自应用程序,而不是库,但它实际上只是一个副本),但它非常简单。我只是想知道应该如何调整它才能调用 lib 中正确的类...
<!--
Only C2DM servers can send messages for the app. If permission is
not set - any other app can generate it
-->
<receiver
android:name="com.google.android.c2dm.C2DMBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<!-- Receive the actual message -->
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="com.myapp.lib" />
</intent-filter>
<!-- Receive the registration id -->
<intent-filter>
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="com.myapp.lib" />
</intent-filter>
</receiver>
其中 com.myapp.lib 是我的 lib 包名称,接收器位于名称相同的包中(在 lib 项目中) , 当然)。
预先感谢您的帮助,请随时询问更多详细信息:)
编辑: 我尝试仅使用在 google C2DM 上注册的库,也尝试使用应用程序和库。同样的问题
I'm currently working on a libproject (Android) that should be included inside a few other applications.
Everything is working fine now that I've been struggling a bit with Activities and Manifests, exept for the C2DM bit.
I can invoke my different classes fine, but I can't seem to catch the registration ID (or of course actual messages, but that must be the same problem...)
I think the problem is coming from the filtering in my manifest(s), so if anyone has any advice for me, that would be really helpful.
Here is a copy of receiver part of my manifest (from the apps, not the library, but it's actually just a copy), but it's pretty straighforward. I just want to know how I should adapt it in order to invoke the right class in the lib...
<!--
Only C2DM servers can send messages for the app. If permission is
not set - any other app can generate it
-->
<receiver
android:name="com.google.android.c2dm.C2DMBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<!-- Receive the actual message -->
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="com.myapp.lib" />
</intent-filter>
<!-- Receive the registration id -->
<intent-filter>
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="com.myapp.lib" />
</intent-filter>
</receiver>
Where com.myapp.lib is my lib package name, and the receiver is in a package named the same (in the lib project, of course).
Thanks in advance for the help, and don't hesitate to ask for furthers details :)
Edit :
I tried with only the lib registered on google C2DM, and also with both app and lib. Same problem
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
有一种更好的方法可以通过使用意图过滤器从库项目中使用 C2DM。
清单文件是来自应用程序的文件。
lib 的包是 com.mylib,应用程序的包是 com.myapp。
lib 清单中有两处需要更改。
两者都应该是您的应用程序包,而不是您的 lib 包。
There is a better way of using your C2DM from a library project by using the intent-filter.
The manifest file is the one from the app.
The package for the lib is com.mylib and the one for the app is com.myapp.
There is 2 things to change from the lib manifest.
Both should be you app package and not your lib package.
答案,是否有人偶然发现同样的问题...
在 google.android.c2dm 包中,类 C2DMBaseReceiver,方法 runIntentInService,
使用完全限定名称进行更改..然后就可以了:)
Answer, is anyone stumble upon the same problem...
In the google.android.c2dm package, class C2DMBaseReceiver, method runIntentInService, change
with the fully qualified name.. and there you go :)
清单看起来不错。在您的包中,您应该有一个名为 C2DMReceiver 的类,并且它应该扩展 C2DMBaseReceiver。然后,在成功注册和收到消息时调用该类及其包含的重写方法。我写了一个非常基本的示例,参考此处可能会对您有所帮助
The manifest looks fine. In your package you should have a class called C2DMReceiver and it should extend C2DMBaseReceiver. This class and the overridden methods it contains are then called upon successful registration and when a message is received. I have written a very basic example of this that may be helpful for you to refer to here