Search code examples
androidandroid-serviceandroid-2.3-gingerbread

The onBind method: how to make it selective?


I would like that only certain applications can perform bind to a service. Can I prevent some applications to bind to a service via suitable code in the service? For example, if the service has a list of allowed applications (ie, a simple string array with their package names), could allow binding only to applications that are listed?


Solution

  • You can define a permission in the androidmanifest.xml under the element <service> using android:permission. Have a look at http://developer.android.com/guide/topics/manifest/service-element.html.