I need to search for bluetooth devices inside a bounded service using the startdiscovery function. For this you need to install a broadcast receiver inside the service. But this requires getting the context, and the bound service does not have it. Static creation of the receiver through the manifest also requires ultimately the presence of context in the receiver.

<receiver android:name=".SingBroadcastReceiver" android:exported="true"> <intent-filter> <action android:name="android.intent.action,ACTION_FOUND"/> </intent-filter> </receiver> 

Is there a way to do this in a tied service?

  • I need to search for bluetooth devices inside a bounded service using the startdiscovery function. For this you need to install a broadcast receiver inside the service. But this requires getting the context, and the bound service does not have it. Static creation of the receiver through the manifest also requires ultimately the presence of context in the receiver. Is there a way to do this in a tied service? - Vladimir Afanasyev
  • And what is wrong with the context in the service and the receiver? The service itself is a descendant of the context, and it comes to the receiver as a parameter when receiving an event - woesss
  • To register a broadcast receiver, a context is already needed. And we are talking about the associated remote service (built on AIDL), you cannot send the context to it - I understand this is not parcelable.type. - Vladimir Afanasyev
  • The context of the service gives the system, just as the activity. There is no need to send it there - the service itself is the context. - woesss
  • Attached service has its own apk. I need to register the receiver, statically through the manifest it fails (see above). Dynamically - I have to get a reference to the context, because the registration method requires a context method. Then the question to you is how to get the context for registering the receiver in the associated service. So is there - ((Context) this) .registerReceiver (.....)? - Vladimir Afanasyev

0