共享库项目的清单服务和权限 [英] Share library project's manifest services and permissions

查看:157
本文介绍了共享库项目的清单服务和权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想开发一个库项目它由GCMIntentService和它执行GCM注册过程,并接收发送GCM消息。

I want to develop a library project which consists of a GCMIntentService and it performs GCM registration process and receives messages sent over GCM.

我已经使用AIDL揭露我的库项目服务托管的应用程序,但我需要声明的应用项目还服务.....我怎样才能避免这种情况?
此外,我需要申报所需的所有GCM的应用程序清单过于权限。
是否有从库中项目的所有权限和服务可以从主机应用程序中引用,而无需在清单中再次声明他们什么办法?

I have used AIDL to expose my library project service to host application,but I need to declare the service in application project also..... How can I avoid this?
Also I needed to declare all the permissions required for GCM in application manifest too.
Is there any way in which all permissions and services from library project can be referenced from host application without having to declare them again in the manifest?

我已搜查了这一点,并发现:
1。<一个href="http://stackoverflow.com/questions/12591115/is-it-possible-encapsulate-permission-inside-android-framework-library">Is它Android框架(库)内可以封装许可
其中明确表示,我想要实现是不可能的。
2.一些有用的<一个href="http://stackoverflow.com/questions/4457219/library-project-does-the-manifest-file-merge">Library项目确实清单文件合并? 通过@Hayes豪根回答说:合并的Andr​​oidManifest.xml中支持的ADT工具20版
我使用的ADT版本20.0.3

I have searched over this and found:
1. Is it possible encapsulate permission inside Android framework (library)
Which clearly says that what I'm trying to achieve is not possible.
2. Something useful Library Project does the manifest file merge? The answer by @Hayes Haugen says that "AndroidManifest.xml merging is supported in version 20 of the ADT tools"
I'm using ADT version 20.0.3

反正是有,我可以得到具有库项目提供GCM整合?

Is there anyway I can achieve having library project providing GCM integration?

推荐答案

你得到了什么错误?

这是伟大的工作对我来说:

This is working great for me:

库清单

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="org.plasync.client.android"
          android:versionCode="1"
          android:versionName="1.0">
    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />

    <uses-permission android:name="android.permission.INTERNET" />
    <!-- Needed for devices with 4.02 or earlier android -->
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
    <permission android:name="org.plasync.client.android.permission.C2D_MESSAGE"
        android:protectionLevel="signature" />
    <uses-permission android:name="org.plasync.client.android.permission.C2D_MESSAGE" />
   <!-- <uses-permission android:name="com.playsnc.client.android.data.permission.READ_WRITE"/>-->

    <application android:label="" android:icon="@drawable/ic_launcher">
        <!-- This is the signin activity for plAsync -->
        <activity android:name="org.plasync.client.android.AsyncMultiplayerSetupActivity"
                  android:label="@string/SETUP_ACTIVITY_NAME"
                  android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen">

            <!-- This is the intent for getting the local user.  Apps that use plAsync must use this
                 intent to retrieve the local user, or allow the user to signin.  Apps should
                 use startActivityForResult as the sigin activity may require user interaction -->
            <intent-filter>
                <action android:name="@string/SETUP_ASYNC_MULTIPLAYER_SESSION_ACTION"/>
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>

        <receiver android:name="org.plasync.client.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" />
            </intent-filter>
        </receiver>

        <service android:name="org.plasync.client.android.gcm.GcmReceiveIntentLauncher"/>
    </application>
</manifest>

应用程序清单

Application Manifest

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

    <uses-sdk
        android:minSdkVersion="11"
        android:targetSdkVersion="17" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme">
        <activity
            android:name="org.plasync.client.android.testapp.AsyncMultiplayerTestAppActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity android:name=".search.FriendSearchActivity"
                  android:launchMode="singleTop">
            <intent-filter>
                <action android:name="android.intent.action.SEARCH" />
            </intent-filter>
            <meta-data android:name="android.app.searchable"
                android:resource="@xml/searchable"/>
        </activity>

        <service android:name=".AsyncMultiplayerTestAppMessageReceiver"/>
    </application>

</manifest>

另外,我不知道你的服务和AIDL的解决方案是矫枉过正。我开始沿着这条道路,但得到了我的情况的进程间通信的复杂性关闭。我已经能够简单地定义在我的图书馆,在我的应用程序将启动一个意图服务的广播接收器和意图的服务。你一定要小心包名。和组件的名称。包名称将永远是你的应用程序软件包名,但该组件名称将是您的服务类名。

Also, I wonder if you solution with services and AIDL is overkill. I started down that route, but got turned off by the complexity of the interprocess communication for my situation. I have been able to simply define a broadcast receiver and intent service in my library, that launches an intent service in my app. You just have to be careful with package names. and component names. The package name will always be the package name for your app, but the component name will be the class name for your service.

这篇关于共享库项目的清单服务和权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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