Notifications & Alarms.  Notifications  Alarms.

Slides:



Advertisements
Similar presentations
Android Application Development Tutorial. Topics Lecture 6 Overview Programming Tutorial 3: Sending/Receiving SMS Messages.
Advertisements

Programming with Android: System Services Luca Bedogni Marco Di Felice Dipartimento di Scienze dell’Informazione Università di Bologna.
Programming with Android: Notifications, Threads, Services
Copyright© Jeffrey Jongko, Ateneo de Manila University Dialogs, Custom Dialogs, Toasts.
CSS216 MOBILE PROGRAMMING Android, Chapter 9 Book: “Professional Android™ 2 Application Development” by Reto Meier, 2010 by: Andrey Bogdanchikov (
All About Android Introduction to Android 1. Creating a New App “These aren’t the droids we’re looking for.” Obi-wan Kenobi 1. Bring up Eclipse. 2. Click.
Cosc 4755 Android Notifications. There are a couple of ways to notify users with interrupting what they are doing The first is Toast, use the factory.
BroadcastReceiver.  Base class for components that receive and react to events  Events are represented as Intent objects  Intents received as parameter.
Application Fundamentals. See: developer.android.com/guide/developing/building/index.html.
User Interface Android Applications. Activities An activity presents a visual user interface. Each activity is given a default window to draw in. The.
Cosc 4730 Android Dialogs and notifications. Notifications There are a couple of ways to notify users without interrupting what they are doing The first.
System broadcasts and services. System broadcast events. EventDescription Intent.ACTION_BOOT_COMPLETEDBoot completed. Requires the android.permission.RECE.
By: Jeremy Smith.  Introduction  Droid Draw  Add XML file  Layouts  LinearLayout  RelativeLayout  Objects  Notifications  Toast  Status Bar.
Programming with Android: Notifications, Threads, Services Luca Bedogni Marco Di Felice Dipartimento di Scienze dell’Informazione Università di Bologna.
Cosc 4730 Android TabActivity and ListView. TabActivity A TabActivity allows for multiple “tabs”. – Each Tab is it’s own activity and the “root” activity.
Android development the first app. Andoid vs iOS which is better? Short answer: neither Proponents on both sides For an iOS side, see this article on.
Developing Push Notifications (C2DM) for Android Vijai Co-Founder Adhish Technologies, Sweet’N’Spicy apps.
Mobile Programming Lecture 2 Layouts, Widgets, Toasts, and Event Handling.
Mobile Computing Lecture#08 IntentFilters & BroadcastReceivers.
Chapter 2: Simplify! The Android User Interface
8. Notification과 Alarm.
Homescreen Widgets Demystified Pearl AndroidTO // Oct 26, 2010.
Mobile Programming Lecture 17 Creating Homescreen Widgets.
Cosc 5/4730 Broadcast Receiver. Broadcast receiver A broadcast receiver (short receiver) – is an Android component which allows you to register for system.
Mobile Programming Lecture 6
1 Announcements Homework #2 due Feb 7 at 1:30pm Submit the entire Eclipse project in Blackboard Please fill out the when2meets when your Project Manager.
1 Mobile Software Development Framework: Android 2/28/2011 Y. Richard Yang.
Mobile Computing Lecture#11 Adapters and Dialogs.
Chapter 2 The Android User Interface. Objectives  In this chapter, you learn to:  Develop a user interface using the TextView, ImageView, and Button.
Android Dialog Boxes AlertDialog - Toast
Threads and Services. Background Processes One of the key differences between Android and iPhone is the ability to run things in the background on Android.
Cosc 5/4730 Android App Widgets. App Widgets App Widgets are miniature application views that can be embedded in other applications (such as the Home.
Create Navigation Drawer Team 2 Zhong Wang Jiaming Dong Philip Wu Lingduo Kong.
Android - Broadcast Receivers
Android Boot Camp for Developers Using Java, Comprehensive: A Guide to Creating Your First Android Apps Chapter 2: Simplify! The Android User Interface.
User notification Android Club Agenda Toast Custom Toast Notification Dialog.
Notifications. A notification is a message you can display to the user outside of your application's normal UI. When you tell the system to issue a notification,
Themes and Menus: The Sudoku Example Content taken from book: “Hello, Android” by Ed Burnette Third Edition.
Android Using Menus Notes are based on: The Busy Coder's Guide to Android Development by Mark L. Murphy Copyright © CommonsWare, LLC. ISBN:
Mobile Programming Lecture 7 Dialogs, Menus, and SharedPreferences.
Android and s Ken Nguyen Clayton state University 2012.
User Interface Layout Interaction. EventsEvent Handlers/Listeners Interacting with a user.
More App Customizations. Overview  Application/ Activity Customizations: Themes  Menu Customizations  Custom Dialogs  Custom Toasts  Custom Buttons.
Mobile Programming Lecture 4 Resources, Selection, Activities, Intents.
Mobile Software Development for Android - I397 IT COLLEGE, ANDRES KÄVER, WEB:
Cosc 4735 Nougat API 24+ additions.
Chapter 2: Simplify! The Android User Interface
Android Programming - Features
Mobile Software Development for Android - I397
Lecture 3 Zablon Ochomo Android Layouts Lecture 3 Zablon Ochomo
CS499 – Mobile Application Development
GUI Programming Fundamentals
Android – Event Handling
Mobile Application Development BSCS-7 Lecture # 8
Android Notifications
S.RENUKADEVI/AP/SCD/ANDROID - AlarmManager
Android Widgets 1 7 August 2018
Android Dialog Boxes AlertDialog - Toast
Android Programming Lecture 6
Android Notifications (Part 1)
Android Notifications (Part 2) Plus Alarms and BroadcastReceivers
Lesson 9 Dialog Boxes & Toast Widgets Victor Matos
Mobile Computing With Android ACST 4550 Toast
CIS 470 Mobile App Development
Android Developer Fundamentals V2
Android Notifications
Android Developer Fundamentals V2 Lesson 5
Notifying from the Background
Android Sensor Programming
Android Sensor Programming
Presentation transcript:

Notifications & Alarms

 Notifications  Alarms

 Used to notify users of events  Three general forms of Notifications  Toast  Dialogs  Status Bar Notifications

 Transitory messages that pop up on the current window  Automatically fade into &out of view  No user interaction or response

 Instantiate a Toast object using makeText()  Parameters - (context, text, duration)  Can create customized layouts in XML  Set them using Toast.setView()

Context context = getApplicationContext(); CharSequence text = ”Message to Display"; int duration = Toast.LENGTH_SHORT; Toast toast = Toast.makeText(context, text, duration); toast.show();

<LinearLayout … android:orientation="horizontal” android:layout_width="fill_parent” android:layout_height="fill_parent" android:padding=" 10 dp” android:background="#7777” > <ImageView android:layout_width="wrap_content” android:layout_height="fill_parent” android:layout_marginRight=" 10 dp” /> <TextView android:layout_width="wrap_content” android:layout_height="fill_parent” android:textColor="#FFF” android:text="I'm Watching You!” />

public class NotificationToastActivity extends Activity { public void onCreate(Bundle savedInstanceState) { … setContentView(R.layout.main); LayoutInflater inflater = getLayoutInflater(); View layout = inflater.inflate( R.layout.custom_toast, (ViewGroup) findViewById(R.id.toast_layout_root)); Toast toast = new Toast(getApplicationContext()); toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0 ); toast.setDuration(Toast.LENGTH_LONG); toast.setView(layout); toast.show(); }

 Created & displayed as part of an Activity  Shown & removed using showDialog() & dismissDialog()  Can define action to perform on dismissal using DialogInterface.OnDismissListener interface  void onDismiss(DialogInterface dialog)  See UI lesson for examples

User transfers to another Activity

 System service that manages Notifications  e.g., notify & cancel

public static class MyService extends Service { private static final int NOTIFICATION_ONE = 1; … public void onStart(Intent intent, int startId) { … int icon = android.R.drawable.stat_sys_warning; CharSequence tickerText = "Notification"; long when = System.currentTimeMillis(); Notification notification = new Notification(icon, tickerText, when); …

Context context = getApplicationContext(); CharSequence contentTitle = "My Notification"; CharSequence contentText = "You've got notifications!"; Intent notificationIntent = new Intent(this,NotificationStatusBarActivity.class); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0 ); notification.setLatestEventInfo( context, contentTitle, contentText,contentIntent); …

NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); mNotificationManager.notify(NOTIFICATION_ONE, notification); …

 To use the user's default sound  notification.defaults |= Notification.DEFAULT_SOUND;  To use a different sound  notification.sound = Uri.parse("file:///sdcard/media/audio/notifications/rooster_2.mp3");

 To use the user's default vibration pattern  notification.defaults |= Notification.DEFAULT_VIBRATE;  To use a different vibration pattern  long[] vibrate = { 0, 100, 200, 300 };  notification.vibrate = vibrate;

 To use the user's default lighting  notification.defaults |= Notification.DEFAULT_LIGHTS;  To use a different lighting  notification.ledARGB = 0 xff00ff00;  notification.ledOnMS = 300 ;  notification.ledOffMS = 1000 ;  notification.flags |= Notification.FLAG_SHOW_LIGHTS;

 Mechanism for broadcasting Intents at predetermined times  Used to start Activities at a specific time or perform actions at periodic time intervals  Once set Alarms remain active even if target application is inactive or asleep  Can optionally be set to wake the device  Canceled on device shutdown/restart

 Example methods  void cancel(PendingIntent operation)  void set(int type, long triggerAtTime, PendingIntent operation)  void setRepeating(int type, long triggerAtTime, long interval, PendingIntent operation)  void setInexactRepeating(int type, long triggerAtTime, long interval, PendingIntent operation)

 RTC_Wakeup  Wakes device, fires Intent at the specified clock time  RTC  Doesn’t wake device, fires Intent at the specified clock time  ELAPSED_REALTIME  Doesn’t wake device, fires Intent at the specified time (interpreted relative to time since last boot)  ELAPSED_REALTIME_WAKEUP  Wakes device, fires Intent at the specified time (interpreted relative to time since last boot)

public void onCreate(Bundle savedInstanceState) { … alarmSetButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { Intent intent1 = new Intent(AlarmCreateActivity.this,ScoldActivity.class); intent1.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent sender1 = PendingIntent.getActivity( AlarmCreateActivity.this, 0, intent1, PendingIntent.FLAG_UPDATE_CURRENT); Intent intent2 = new Intent( AlarmCreateActivity.this,AlarmCancelReceiver.class); PendingIntent sender2 = PendingIntent.getBroadcast( AlarmCreateActivity.this, 0, intent2, PendingIntent.FLAG_UPDATE_CURRENT); …

AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE); Calendar cal = Calendar.getInstance(); am.setRepeating( AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(),10000, sender1); am.set( AlarmManager.RTC_WAKEUP, cal.getTimeInMillis() ,sender2); …

public class ScoldActivity extends Activity { protected void onCreate(Bundle savedInstanceState) { … Toast.makeText(this, "Are you playing Angry Birds again?", Toast.LENGTH_LONG).show(); }

public class AlarmCancelReceiver extends BroadcastReceiver { public void onReceive(Context context, Intent intent) { Intent newIntent = new Intent(context, ScoldActivity.class); PendingIntent sender = PendingIntent.getActivity( context, 0, newIntent, PendingIntent.FLAG_UPDATE_CURRENT); final AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); am.cancel(sender); }