Android Notifications

Slides:



Advertisements
Similar presentations
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.
Advertisements

Notifications & Alarms.  Notifications  Alarms.
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.
Basic, Basic, Basic Android. What are Packages? Page 346 in text Package statement goes before any import statements Indicates that the class declared.
Android Application Development with Java UPenn CS4HS 2011 Chris Murphy
@2011 Mihail L. Sichitiu1 Android Introduction Hello World.
Chien-Chung Shen Manifest and Activity Chien-Chung Shen
Introduction to Android Programming Content Basic environmental structure Building a simple app Debugging.
Wireless Mobility with Android 1 Presented by: Ung Yean MS. Computer Science American University, Washington DC, USA.
Mobile Computing Lecture#08 IntentFilters & BroadcastReceivers.
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.
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.
Android - Broadcast Receivers
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,
1 Introducing Activity and Intent. 2 Memory LinearLayout, weight=2 LinearLayout, weight=1 TextView ListView.
Announcements Homework #2 will be posted after class due Thursday Feb 7, 1:30pm you may work with one other person No office hours tonight (sorry!) I will.
Android App Basics Dr. David Janzen Except as otherwise noted, the content of this presentation is licensed under the Creative Commons Attribution 2.5.
Android Using Menus Notes are based on: The Busy Coder's Guide to Android Development by Mark L. Murphy Copyright © CommonsWare, LLC. ISBN:
Copyright© Jeffrey Jongko, Ateneo de Manila University Deconstructing HelloWorld.
Android and s Ken Nguyen Clayton state University 2012.
Android 基本 I/O. 基本 I/O 介面元件 在此節中主要介紹常見的 I/O 使用者介 面元件 – Button, TextView, 以及 EditText , 學習者可以學會: – Android 的視窗表單設計 res/layout/main.xml – Android SDK –
CMPE419 Mobile Application Development Asst.Prof.Dr.Ahmet Ünveren SPRING Computer Engineering Department Asst.Prof.Dr.Ahmet Ünveren
CMPE419 Mobile Application Development Asst.Prof.Dr.Ahmet Ünveren SPRING Computer Engineering Department Asst.Prof.Dr.Ahmet Ünveren
Android Programming.
Lab7 – Appendix.
Lab7 – Advanced.
Android Programming - Features
Lecture 3 Zablon Ochomo Android Layouts Lecture 3 Zablon Ochomo
Android Introduction Hello World
Android Application Development 1 6 May 2018
Android N Amanquah.
Android Intent Filters
Adapting to Display Orientation
GUI Programming Fundamentals
Android – Event Handling
Activities, Fragments, and Events
Android Introduction Hello World.
Android Notifications
Cleveland State University
CS499 – Mobile Application Development
Android Widgets 1 7 August 2018
Android Introduction Hello Views Part 1.
ITEC535 – Mobile Programming
Android Dialog Boxes AlertDialog - Toast
Android Introduction Camera.
תכנות ב android אליהו חלסצ'י.
CIS 470 Mobile App Development
CIS 470 Mobile App Development
CIS 470 Mobile App Development
CIS 470 Mobile App Development
CIS 470 Mobile App Development
Many thanks to Jun Bum Lim for his help with this tutorial.
CMPE419 Mobile Application Development
BMI Android Application will take weight and height from the users to calculate Body Mass Index (BMI) with the information, whether user is underweight,
Activities and Intents
CIS 470 Mobile App Development
CIS 470 Mobile App Development
CIS 470 Mobile App Development
CIS 470 Mobile App Development
Android Developer Fundamentals V2
CMPE419 Mobile Application Development
CMPE419 Mobile Application Development
Chapter 5 Your Second Activity.
Android Sensor Programming
Android Sensor Programming
CIS 694/EEC 693 Android Sensor Programming
CIS 694/EEC 693 Android Sensor Programming
Presentation transcript:

Android Notifications 23 Android Notifications Victor Matos Cleveland State University Notes are based on: Android Developers http://developer.android.com/index.html

Notifications What is a Notification? 20. Android - Notifications Notifications What is a Notification? A notification is a short message briefly displayed on the status line. It typically announces the happening of an special event for which a trigger has been set. After opening the Notification Panel the user may choose to click on a selection and execute an associated activity.   2 2 2

Notifications What is a Notification? 20. Android - Notifications Notifications What is a Notification?   Notification shown on the status line Drag down Click on Notification Panel to execute associated application 3 3 3

Notifications Notification Manager 20. Android - Notifications Notifications Notification Manager This class notifies the user of events that happen in the background. Notifications can take different forms: A persistent icon that goes in the status bar and is accessible through the launcher, (when the user selects it, a designated Intent can be launched), Turning on or flashing LEDs on the device, or Alerting the user by flashing the backlight, playing a sound, or vibrating. 4 4 4

Notifications Notification Manager 20. Android - Notifications Notifications Notification Manager You do not instantiate this class directly; instead, retrieve it through getSystemService ( String ). Example: String servName = Context.NOTIFICATION_SERVICE; notificationManager = (NotificationManager) getSystemService (servName);   5 5 5

Notifications Notification 20. Android - Notifications Notifications Notification This class represents how a persistent notification is to be presented to the user using the NotificationManager. public Notification (int icon, CharSequence tickerText, long when) Parameters icon The resource id of the icon to put in the status bar. tickerText The text that flows by in the status bar when the notification first activates. when The time to show in the time field. In the System.currentTimeMillis timebase.   6 6 6

Notifications Notification - Methods 20. Android - Notifications Notifications Notification - Methods public void notify (int id, Notification notification) Places a persistent notification on the status bar. Parameters id An identifier for this notification unique within your application. notification A Notification object describing how to notify the user, other than the view you're providing. Must not be null.   7 7 7

Notifications Notification – Methods public void setLatestEventInfo ( 20. Android - Notifications Notifications Notification – Methods public void setLatestEventInfo ( Context context, CharSequence contentTitle, CharSequence contentText, PendingIntent contentIntent) Sets the contentView field to be a view with the standard "Latest Event" layout. Parameters context The context for your application / activity. contentTitle The title that goes in the expanded entry. contentText The text that goes in the expanded entry. contentIntent The intent to launch when the user clicks the expanded notification.   8 8 8

Notifications Notification – Methods public void cancel ( int id ) 20. Android - Notifications Notifications Notification – Methods public void cancel ( int id ) public void cancelAll ( ) Cancel a previously shown notification. If it's transient, the view will be hidden. If it's persistent, it will be removed from the status bar. Parameters Id An identifier for this notification unique within your application.   9 9 9

Notifications Example. 20. Android - Notifications Notifications Example. Produce a notification. Allow the user to click on the Notification Panel and execute appropriate activity to attend the message.   10 10 10

Notifications Example - Layouts main2.xml main.xml 20. Android - Notifications Notifications Example - Layouts   main2.xml main.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout android:id="@+id/main2LinLayout" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#ff660000" android:orientation="vertical" xmlns:android="http://schemas.android.com/apk/res/android" > <TextView android:id="@+id/widget29" android:layout_width="251px" android:layout_height="69px" android:text="Hola this is screen 2 - Layout:main2.xml" </TextView> </LinearLayout> <?xml version="1.0" encoding="utf-8"?> <LinearLayout android:id="@+id/myLinearLayout1" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#ff000066" android:orientation="vertical" xmlns:android="http://schemas.android.com/apk/res/android" > <Button android:id="@+id/btnGo" android:layout_width="106px" android:layout_height="61px" android:layout_margin="10px" android:text=" Show Notification " > </Button> android:id="@+id/btnStop" android:text=" Cancel Notification " > </LinearLayout> 11 11 11

Notifications Example – Manifest /drawable Note: 20. Android - Notifications Notifications Example – Manifest /drawable   <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="cis493.demos" android:versionCode="1" android:versionName="1.0"> <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".NotifyDemo1" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".NotifyHelper" > </application> <uses-sdk android:minSdkVersion="4" /> </manifest> btn_star_big_on_selected.png Note: Obtain the icon from the folder C:\Android\platforms\android-1.x\data\res\drawable 12 12 12

Notifications Example – Create & Cancel a Notification 20. Android - Notifications Notifications Example – Create & Cancel a Notification   package cis493.demos; import android.app.Activity; import android.app.Notification; import android.app.NotificationManager; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.*; /////////////////////////////////////////////////////////////////////////////// public class NotifyDemo1 extends Activity { Button btnGo; Button btnStop; int notificationId = 1; NotificationManager notificationManager; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); 13 13 13

Notifications Example – Create & Cancel a Notification 20. Android - Notifications Notifications Example – Create & Cancel a Notification   btnGo = (Button)findViewById(R.id.btnGo); btnGo.setOnClickListener(new OnClickListener() { public void onClick(View v) { //define a notification manager String serName = Context.NOTIFICATION_SERVICE; notificationManager = (NotificationManager)getSystemService(serName); //define notification using: icon, text, and timing. int icon = R.drawable.btn_star_big_on_selected; String tickerText = "1. My Notification TickerText"; long when = System.currentTimeMillis(); Notification notification = new Notification(icon, tickerText, when); //configure appearance of the notification String extendedTitle = "2. My Extended Title"; String extendedText = "3. This is an extended and very important message"; // set a Pending Activity to take care of the potential request the user // may have by clicking on the notification asking for more explanations Intent intent = new Intent(getApplicationContext(), NotifyHelper.class); intent.putExtra("extendedText", extendedText); intent.putExtra("extendedTitle", extendedTitle); PendingIntent launchIntent = PendingIntent.getActivity(getApplicationContext(),0,intent,0); 14 14 14

Notifications Example – Create & Cancel a Notification 20. Android - Notifications Notifications Example – Create & Cancel a Notification   notification.setLatestEventInfo(getApplicationContext(), extendedTitle, extendedText, launchIntent); //trigger notification notificationId = 1; notificationManager.notify(notificationId, notification); }//click }); ///////////////////////////////////////////////////////////////////////////// btnStop = (Button)findViewById(R.id.btnStop); btnStop.setOnClickListener(new OnClickListener() { public void onClick(View v) { //canceling a notification notificationManager.cancel(notificationId); } }//onCreate }//NotifyDemo1 15 15 15

Notifications Example - SubActivity – Attending the Notification 20. Android - Notifications Notifications Example - SubActivity – Attending the Notification   package cis493.demos; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.widget.Toast; public class NotifyHelper extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main2); Intent myData = getIntent(); // extract the extra-data in the Notification String msg = myData.getStringExtra("extendedTitle") + "\n" + myData.getStringExtra("extendedText"); Toast.makeText(getApplicationContext(), msg, 1).show(); } 16 16 16

20. Android - Notifications Questions 17 17