Search code examples
android-sourceandroid-buildandroid-framework

BroadcastReceiver - cannot find registerReceiver inside SystemSensorManager


I want to use BroadcastReceiver inside SystemSensorManager class (android.hardware). I managed to define an object of type BroadcastReceiver but when I tried to register this receiver using :

registerReceiver(BroadcastReceiver receiver, IntentFilter filter) 

This method cannot be found and the source code doesnt compile.

I tried the to do similar thing in the Activity class and it succeeded. whats wrong with the SystemSensorManager class ?


Solution

  • registerReceiver is defined on Context and its descendants. SystemSensorManager receives context in constructor, but does not remember it. You should find a relevant Context for your change.