You would certainly have to keep around something that monitors sensor data, like a background Service. You service must continuously monitor sensor events, pass it through a noise filter, detect a shake and send out a Broadcast.
The Activity on the other hand can implement a matching BroadcastReciever.
If you don't want to add BroadcastRecievers for Activities, then you can just register interested activities in init()
code of library:
public void init(Context context){
SensorTester st = new SensorTester(context);
st.registerActivity(MainActivity.class);
st.registerActivity(OtherActivity.class);
}
And start them from library service using the Context you received in init()
code:
for(Class c : registeredClasses){
context.startActivity(new Intent(this,c));
}
Where you want to place init()
code in target App is your choice.