Android的C2DM和lib项目 [英] Android C2DM and lib project

查看:122
本文介绍了Android的C2DM和lib项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前工作的一个libproject(Android版)应该包括内部一些其他的应用程序。

I'm currently working on a libproject (Android) that should be included inside a few other applications.

一切现在工作的罚款,我一直在挣扎了一下活动场所和舱单,exept的C2DM位。

Everything is working fine now that I've been struggling a bit with Activities and Manifests, exept for the C2DM bit.

我可以调用我的不同类别的很好,但我似乎无法赶上注册ID(或课程的实际消息,但必须是同样的问题...)

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...)

我认为这个问题是从过滤进来我的清单(S),因此,如果任何人有任何的意见对我来说,这将是真正的帮助。

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.

下面是我的清单的接收器部分的副本(从应用程序,而不是图书馆,但它实际上只是一个复印件),但它是pretty简单明了。我只是想知道我应该怎么才能调用在lib合适的班级适应它...

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>

在哪里com.myapp.lib是我的lib包名称,而接收器是在一个名为同一个包(在lib项目,当然)。

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 :)

编辑:
我想,只有在谷歌C2DM注册的lib,同时还与两个应用程序和库。同样的问题

Edit : I tried with only the lib registered on google C2DM, and also with both app and lib. Same problem

推荐答案

有是使用C2DM从库项目的使用意图过滤器更好的方法。

There is a better way of using your C2DM from a library project by using the intent-filter.

清单文件是从应用程序之一。
该包的lib是com.mylib和一个用于应用程序是com.myapp。

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.

有2件事,从LIB明显改变。

There is 2 things to change from the lib manifest.


  1. 在权限中使用的类路径。

  2. 意向过滤包。

这两个应该是你的应用程序包,而不是你的lib包。

Both should be you app package and not your lib package.

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

<permission android:name="com.myapp.permission.C2D_MESSAGE" android:protectionLevel="signature" />

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

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

     <uses-library android:name="com.google.android.maps" android:required="true"/>



    <activity
        android:name=".MyActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>


     <receiver
        android:name="com.mylib.C2DMRegistrationReceiver"
        android:permission="com.google.android.c2dm.permission.SEND" >
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.REGISTRATION" >
            </action>
            <category android:name="com.myapp" /> 
        </intent-filter>
    </receiver>

    <receiver
        android:name="com.mylib.C2DMMessageReceiver"
        android:permission="com.google.android.c2dm.permission.SEND" >
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE" >
            </action>
           <category android:name="com.myapp" /> 
        </intent-filter>
    </receiver>
</application>
</manifest>

这篇关于Android的C2DM和lib项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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