android service exported attribute?

前端 未结 2 1367
隐瞒了意图╮
隐瞒了意图╮ 2021-02-18 16:53

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

相关标签:
2条回答
  • 2021-02-18 17:05

    You can will find that the sample applications SampleSyncAdapter, CubeLiveWallpaper, and VoiceRecognitionService (new in level 8) all export services for public use. You can look through your sdk's samples/ directory. Eclipse can create a new project using the existing samples (from the File/New/Android Project dialog).

    0 讨论(0)
  • 2021-02-18 17:18

    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
    
    0 讨论(0)
提交回复
热议问题