我对Android平台很新。我想将我的服务导出为公开使用。 我在开发人员doc上找到了一些东西
android:exported
其他应用程序的组件是否可以调用服务或与之交互 - 如果可以,则为“true”,否则为“false”。当值为“false”时,只有相同应用程序的组件或具有相同用户ID的应用程序才能启动服务或绑定到该服务。
但我不明白 有人能告诉我一个如何使用它的简短例子吗?
答案 0 :(得分:10)
"导出的目的"是让其他应用程序可以访问服务。
例如,\ android-sdk-windows \ samples \ android-8 \ SampleSyncAdapter \ AndroidManifest.xml
<service
android:name=".authenticator.AuthenticationService"
android:exported="true">
<intent-filter>
<action
android:name="android.accounts.AccountAuthenticator" />
</intent-filter>
<meta-data
android:name="android.accounts.AccountAuthenticator"
android:resource="@xml/authenticator" />
</service>
<service
android:name=".syncadapter.SyncService"
android:exported="true">
<intent-filter>
<action
android:name="android.content.SyncAdapter" />
</intent-filter>
<meta-data
android:name="android.content.SyncAdapter"
android:resource="@xml/syncadapter" />
<meta-data
android:name="android.provider.CONTACTS_STRUCTURE"
android:resource="@xml/contacts" />
</service>
然后可以在
的samples文件夹中找到与这些服务匹配的源代码\ Android的SDK窗口\样品\机器人-8 \ SampleSyncAdapter \ SRC \ COM \示例\机器人\ samplesync \鉴权\ AuthenticationService.java
和
\ Android的SDK窗口\样品\机器人-8 \ SampleSyncAdapter \ SRC \ COM \示例\机器人\ samplesync \ syncadapter \ SyncService.java
使用它的示例可能位于...
\android-sdk-windows\samples\android-8\SampleSyncAdapter\src\com\example\android\samplesync\client\NetworkUtilities.java (3 hits)
Line 63: "https://samplesyncadapter.appspot.com";
Line 238: // Succesfully connected to the samplesyncadapter server and
Line 287: // Succesfully connected to the samplesyncadapter server and
答案 1 :(得分:0)
您可以找到示例应用程序SampleSyncAdapter,CubeLiveWallpaper和VoiceRecognitionService(级别8中的新增内容)所有导出服务以供公共使用。您可以浏览您的sdk的samples /目录。 Eclipse可以使用现有示例(来自File / New / Android Project对话框)创建一个新项目。