Broadcast Receiver Android Club 2015
Agenda Broadcast Receiver Widget
BroadcastReceiver: 4 steps Register BroadcastReceiver Broadcast an Intent Android delivers Intent to BroadcastReceiver onReceive()
2 types of registration Static Dynamic
Static registration: example
Static registration: practice AndroidManifest.xml: create receiver Create intent-filter with TIMEZONE_CHANGED action Create BroadcastReceiver: show Toast “Time zone changed”
Dynamic registration: example IntentFilter receiverFilter = new IntentFilter(Intent.ACTION_HEADSET_PL UG); HeadsetPlugReceiver receiver = new HeadsetPlugReceiver(); registerReceiver(receiver, receiverFilter);
Dynamic registration: practice Create intent with ACTION_USER_PRESENT Create BroadcastReceiver: UnlockReceiver registerReceiver In reciver show toast “Welcome back, [YOUT_NAME]
Widget: example ComponentName watchWidget = new ComponentName(context, ClubWidget.class); Intent intent = new Intent(context, ClubWidget.class); intent.setAction(WIFI_WIDGET_CLICKED); PendingIntent pending = PendingIntent.getBroadcast(context, 0, intent, 0); views.setOnClickPendingIntent(R.id.appwidget_te xt, pending); appWidgetManager.updateAppWidget(appWidgetI d, views);
Widget: practice Create App Widget: TossWidget On layout put ImageView with Toss When user click toss, show Toast values from 1 to 6 Random r = new Random(); int value = r.nextInt(6)+1;
Homework Create Widget It should have 1 ImageView, 1 Button When user clicks on button ImageView image should be changed
Questions? Any questions?
Thank you Thank you for your attention