Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Register broadcastreceiver if debug
/**
* Test broadcast receiver used only for debug
*/
private BroadcastReceiver testTransitStateReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
logger.debug("Entry");
Log.d("SomeReceiver", "testTransitStateReceiver");
if(TEST_ACTION.equals(intent.getAction())){
String extras = intent.getStringExtra("state");
if("S".equals(extras)){
onTransitStateChanged(TransitState.STATIONARY);
} else if ("T".equals(extras)){
onTransitStateChanged(TransitState.IN_TRANSIT);
} else if ("U".equals(extras)){
onTransitStateChanged(TransitState.UNKNOWN);
}
}
}
};
//Test receiver are only for debug build config
if(BuildConfig.DEBUG){
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(TEST_ACTION);
this.mContext.registerReceiver(testTransitStateReceiver,intentFilter);
}
@rwoloszyn
Copy link
Author

rwoloszyn commented Mar 10, 2016

and sending broadcast from ADB could be made similar to this:
am broadcast "intent:#Intent;action=android.intent.action.BATTERY_CHANGED;i.status=5;i.voltage=4155;i.level=100;end"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment