I am quite new to the android platform. I want to export my service to be publicly used. I find something on developer doc
android:exported
Whether or not components of other applications can invoke the service or interact with it — "true" if they can, and "false" if not. When the value is "false", only components of the same application or applications with the same user ID can start the service or bind to it.
but I don't understand it Can anyone show me a brief example of how to use it?
The "exported" attribute describes whether or not someone else can be allowed to use it. So if you have "exported=false" on an Activity, no other app, or even the Android system itself, can launch it. Only you can do that, from inside your own application.
The important part is android:exported="true" , this export tag determines "whether or not the activity can be launched by components of other applications". If your <activity> contains an <intent-filter> then this tag is set to true automatically, if it does not then it is set to false by default.
You declare a service in your app's Manifest, by adding a <service> element as a child of your <application> element. There's a list of attributes that you can use to control a service's behavior, but as a minimum you'll need to provide the service's name (android:name) and a description (android:description).
Declaring a service in the manifest You must declare all services in your application's manifest file, just as you do for activities and other components. To declare your service, add a <service> element as a child of the <application> element.
The purpose of the "exported" is to let other apps have access to a service.
For example, \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>
The source code that matches with these services is then found in your samples folder at
\android-sdk-windows\samples\android-8\SampleSyncAdapter\src\com\example\android\samplesync\authenticator\AuthenticationService.java
and
\android-sdk-windows\samples\android-8\SampleSyncAdapter\src\com\example\android\samplesync\syncadapter\SyncService.java
An example of using this might be located at...
\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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With