Zeb*_*eba 22 android aidl android-library google-cloud-messaging android-permissions
我想开发一个由GCMIntentService组成的库项目,它执行GCM注册过程并接收通过GCM发送的消息.
我已经使用AIDL将我的库项目服务暴露给宿主应用程序,但我还需要在应用程序项目中声明服务.....我该如何避免这种情况?
此外,我还需要在应用程序清单中声明GCM所需的所有权限.
是否有任何方法可以从宿主应用程序中引用库项目的所有权限和服务,而无需在清单中再次声明它们?
我已经搜索过这个并发现:
1.是否可以在Android框架(库)中封装权限
这清楚地表明我想要实现的目标是不可能的.
2.有用的库项目清单文件是否合并?
@Hayes Haugen的回答说"在ADT工具的第20版中支持AndroidManifest.xml合并"
我正在使用ADT版本20.0.3
无论如何我可以实现提供GCM集成的库项目吗?
小智 2
你遇到了什么错误?
这对我来说非常有用:
图书馆清单
<?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>
Run Code Online (Sandbox Code Playgroud)
申请清单
<?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>
Run Code Online (Sandbox Code Playgroud)
另外,我想知道你用服务和 AIDL 解决方案是否有点矫枉过正。我开始沿着这条路线走下去,但由于我的情况的进程间通信的复杂性而放弃了。我已经能够在我的库中简单地定义广播接收器和意图服务,从而在我的应用程序中启动意图服务。您只需要小心包名称即可。和组件名称。包名称将始终是您的应用程序的包名称,但组件名称将是您的服务的类名称。