Download presentation
Presentation is loading. Please wait.
Published byNickolas Houston Modified over 9 years ago
1
Broadcast Receiver Android Club 2015
2
Agenda Broadcast Receiver Widget
3
BroadcastReceiver: 4 steps Register BroadcastReceiver Broadcast an Intent Android delivers Intent to BroadcastReceiver onReceive()
4
2 types of registration Static Dynamic
5
Static registration: example
6
Static registration: practice AndroidManifest.xml: create receiver Create intent-filter with TIMEZONE_CHANGED action Create BroadcastReceiver: show Toast “Time zone changed”
7
Dynamic registration: example IntentFilter receiverFilter = new IntentFilter(Intent.ACTION_HEADSET_PL UG); HeadsetPlugReceiver receiver = new HeadsetPlugReceiver(); registerReceiver(receiver, receiverFilter);
8
Dynamic registration: practice Create intent with ACTION_USER_PRESENT Create BroadcastReceiver: UnlockReceiver registerReceiver In reciver show toast “Welcome back, [YOUT_NAME]
9
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);
10
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;
11
Homework Create Widget It should have 1 ImageView, 1 Button When user clicks on button ImageView image should be changed
12
Questions? Any questions?
13
Thank you Thank you for your attention
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.