0

I can find the way to setup Bound Services in android AIP Guides!

This demo allows any app to bind to it.But what I want is only my apk can communicate with the service I code.Is there any way to do it? How to? Thanks!

2 Answers2

1

Services are not exported by default, meaning they can only be called/bound by your application. Unless you add android:exported="true" to your service's manifest entry, only your app will be able to bind to the service.

ianhanniballake
  • 191,609
  • 30
  • 470
  • 443
  • Yes,I know this.In my case,I want to publish a apk with only a service.This apk may have special permission, e.g. inject key – user3823825 Jul 10 '14 at 06:23
0

Service.onBind() receives intent that was used to bind to your service. One approach is to add an permission extra to the aforementioned intent, check for its value in Service.onBind(), and deny any bind requests in case of invalid permission value.

A.Vynohradov
  • 276
  • 1
  • 8
  • I can add some flag on intent, but the other developer may add the same flag. – user3823825 Jul 10 '14 at 09:02
  • How do they know what is the value of the permission if you're the only one who sets it? – A.Vynohradov Jul 10 '14 at 09:21
  • If I want to know a intent's detail, I would make a new service to catch intent. – user3823825 Jul 10 '14 at 12:05
  • Let me clarify the idea: 1) you [create an intent for a specific component](http://developer.android.com/reference/android/content/Intent.html#Intent%28android.content.Context,%20java.lang.Class%3C?%3E%29) and add permission extra to it; 2) `bindService()` is passed this "targeted" `Intent` and no other receiver can catch it; 3) service checks if _permission_ is valid – A.Vynohradov Jul 10 '14 at 12:21