SMS. Short Message Service – Primarily text messages between mobile phones – First one sent December 3, 1982 “Merry Christmas” – In 2008 Approximately.

Slides:



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

MESSAGING. Overview  SMS sends short text messages between mobile phones.  Supports sending both text messages and data messages  MMS (multimedia messaging.
Manifest File, Intents, and Multiple Activities. Manifest File.
ITEC200 – Week03 Inheritance and Class Hierarchies.
BroadcastReceiver.  Base class for components that receive and react to events  Events are represented as Intent objects  Intents received as parameter.
1 Frameworks. 2 Framework Set of cooperating classes/interfaces –Structure essential mechanisms of a problem domain –Programmer can extend framework classes,
Cosc 5/4730 Android SMS. A note first Depending on the API level, an import changes because of a deprecated API 3 uses – import android.telephony.gsm.SmsManager;
System broadcasts and services. System broadcast events. EventDescription Intent.ACTION_BOOT_COMPLETEDBoot completed. Requires the android.permission.RECE.
Cosc 5/4730 Android SMS and MMS.
SMS Read received SMS Read sent SMS Send SMS New app, SMSFun Button – Text: Send SMS – Id: sendSMSButton Permissions – send_sms – read_sms – receive_sms.
Chien-Chung Shen Manifest and Activity Chien-Chung Shen
Android Declassification Infrastructure Matan David Yuval Evron Project Advisor: Roei Schuster 1.
J2ME Messaging Khanh Le. Objective  The objective of wireless messaging is to extend the networking and I/O capabilities of J2ME applications to send.
 Understanding an activity  Starting an activity  Passing information between activities  Understanding intents  Understanding the activity lifecycle.
© Keren Kalif Intro to Android Development Written by Keren Kalif, Edited by Liron Blecher Contains slides from Google I/O presentation.
CISC6795: Spring Object-Oriented Programming: Polymorphism.
Mobile Computing Lecture#08 IntentFilters & BroadcastReceivers.
Sensing. Possible sensors on devices – Documented in SensorEvent class Accelerometer (m/s 2 ) – acceleration in x, y, z axes Magnetic Field (micro Tesla)
P2P communication Using the GTalk Service API. Introduction Peer-to-Peer communication highly used in mobile devices. Very efficient to when certain factors.
Mobile Programming Lecture 17 Creating Homescreen Widgets.
Integrating with Android Services. Introduction  Android has numerous built-in functionality that can be called from within your applications  SMS/MMS.
Using Intents to Broadcast Events Intents Can be used to broadcast messages anonymously Between components via the sendBroadcast method As a result Broadcast.
Cosc 5/4730 Broadcast Receiver. Broadcast receiver A broadcast receiver (short receiver) – is an Android component which allows you to register for system.
Android ICC Part II Inter-component communication.
COMP 365 Android Development.  Perform operations in the background  Services do not have a user interface (UI)  Can run without appearing on screen.
Mobile Programming Lecture 6
DUE Hello World on the Android Platform.
CS378 - Mobile Computing Intents.
16 Services and Broadcast Receivers CSNB544 Mobile Application Development Thanks to Utexas Austin.
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.
CS378 - Mobile Computing Intents. Allow us to use applications and components that are part of Android System – start activities – start services – deliver.
Android - Broadcast Receivers
Android Boot Camp for Developers Using Java, 3E
More on Hierarchies 1. When an object of a subclass is instantiated, is memory allocated for only the data members of the subclass or also for the members.
Telephony and sms API’S. Objective Telephony ➤ Initiating phone calls ➤ Reading the phone, network, data connectivity, and SIM states ➤ Monitoring changes.
Cosc 5/4730 Android Communications Intents, callbacks, and setters.
Programs and Classes A program is made up from classes Classes may be grouped into packages A class has two parts static parts exist independently Non-static.
Location. GPS Global Positioning System – At least 4 satellites typically used 3 required extra for error detection and altitude typically accurate within.
Android System Security Xinming Ou. Android System Basics An open-source operating system for mobile devices (AOSP, led by Google) – Consists of a base.
Applications with Multiple Activities. Most applications will have more than one activity. The main activity is started when the application is started.
Android - Location Based Services. Google Play services facilitates adding location awareness to your app with automated location tracking Geo fencing.
Chapter 11: Advanced Inheritance Concepts. Objectives Create and use abstract classes Use dynamic method binding Create arrays of subclass objects Use.
Services Background operating component without a visual interface Running in the background indefinitely Differently from Activity, Service in Android.
POLYMORPHISM Chapter 6. Chapter Polymorphism  Polymorphism concept  Abstract classes and methods  Method overriding  Concrete sub classes and.
Intents and Broadcast Receivers Dr. David Janzen Except as otherwise noted, the content of this presentation is licensed under the Creative Commons Attribution.
David Sutton SMS TELEPHONY IN ANDROID. OUTLINE  This week’s exercise, an SMS Pub Quiz  Simulating telephony on an emulator  Broadcast Intents and broadcast.
ANDROID LAYOUTS AND WIDGETS. Slide 2 Introduction Parts of the Android screen Sizing widgets and fonts Layouts and their characteristics Buttons, checkboxes.
Java for android Development Nasrullah Khan. Using instanceof in Android Development the classes such as Button, TextView, and CheckBox, which represent.
Messaging and Networking. Objectives Send SMS messages using the Messaging app Send SMS messages programmatically from within your app Receive and consume.
Cosc 4735 Nougat API 24+ additions.
Lab7 – Appendix.
Intents and Broadcast Receivers
CS499 – Mobile Application Development
Broadcast receivers.
CS371m - Mobile Computing Services and Broadcast Receivers
3 Introduction to Classes and Objects.
Messaging Unit-4.
MAD.
Activities and Intents
Android Mobile Application Development
Sensors, maps and fragments:
Broadcast Receivers A Android Component where you can register for system or application events, receive and react to broadcast intent. Each broadcast.
Developing Android Services
CIS 470 Mobile App Development
Android Notifications (Part 2) Plus Alarms and BroadcastReceivers
CIS 470 Mobile App Development
Android Developer Fundamentals V2 Lesson 5
Java Programming Language
Chapter 5 Your Second Activity.
Mobile Programming Broadcast Receivers.
Presentation transcript:

SMS

Short Message Service – Primarily text messages between mobile phones – First one sent December 3, 1982 “Merry Christmas” – In 2008 Approximately 2.5 billion active users Over 4.1 trillion messages sent – Average cost to users: 0.11USD – Average cost to providers: less than 0.01USD

Components of SMS in Android Manifest file – Permissions – Intent filter Classes within android.telephony package – android.telephony.SmsManager class – android.telephony.SmsMessage class android.content.BroadcastReceiver No Listeners

Manifest file

Permissions uses-permission tags – children of manifest tag – often placed above application tag provides ability to send messages provides ability to receive messages

Intent filter receiver, intent-filter, and action tags – receiver is child of application tag – intent-filter is child of receiver tag – action is child of intent-filter tag intent-filter ‘filters’ all possible components that can be received and delivers only those specified name attribute must be set to the name of class that will be receiving messages – class must be a subclass of BroadcastReceiver

SmsManager class

SmsManager Concrete class Manages SMS activities Needed to send a message – not needed to receive Not instantiated directly – instantiated through the SmsManager getDefault() method SmsManager sm = SmsManager.getDefault();

SmsManager important methods – getDefault returns an instance of SmsManager – sendTextMessage (5 parameters) String indicating destination (i.e. a phone number) String indicating the source (i.e. a phone number) String holding the message 2 PendingIntents – Used when multiple apps are communicating with each other – PendingIntents are Intents that can be handed to other apps with your apps permissions – Here used to pass additional information, or to verify successful communication – 1 st Intent done when message sent, 2 nd when message received only first and third arguments are required – others can be null

Sample code Sending a message //sendTo is a String holding the phone number //message is a String holding the text message SmsManager sm = SmsManager.getDefault(); sm.sendTextMessage(sendTo, null, message, null, null); To send a message, only an SmsManager is needed – BroadcastReceiver and SmsMessage are not used

SmsMessage class

Concrete class Used in conjunction with a BroadcastReceiver to receive messages Represents a specific message Contains: – sender’s phone – message – other information (timestamp, whether or not the message was sent from , etc.)

SmsMessage class important methods – createFromPDU() creates an SmsMessage from a PDU obtained from the BroadcastReceiver PDU – protocol data unit (any transferrable entity) – in our case a message – in other network apps may be an address, packet, etc. – getOriginatingAddress() returns phone number of sender as a String – getMessageBody() returns message as a String

BroadcastReceiver class

Concrete class Receives incoming messages – messages are stored in an Intent created by the transmitter – to obtain SmsMessage – override onReceive method in BroadcastReceiver class: getExtras() method in the Intent class returns a Bundle get(“pdus”) method in the Bundle class returns an Object – must be cast to an Object[] SmsMessage now created via createFromPdu method – use first element in object array, cast to a byte[]

Sample code – receiving a message public class MyBroadcastReceiver extends BroadcastReceiver { public void onReceive(Context context, Intent i) { Bundle b = i.getExtras(); SmsMessage msg = null; String phone = new String(); String message = new String(); if (b != null) { if (b.get("pdus") instanceof Object[]) { Object[] pdus = (Object[])b.get("pdus"); //Large message may be broken up in parts //iterate thru pdus array if necessary msg = SmsMessage.createFromPdu((byte[])pdus[0]); phone = msg.getOriginatingAddress(); message = msg.getMessageBody(); //Code handling the phone and message goes here }

Consequences of not having a Listener

Listening for events Historically 2 approaches – Providing a Listener interface Preferred approach – OnClickListener – LocationListener – SensorEventListener – etc. – Providing the event producer with a handle to the listening object

Sample code – providing a handle to the Listener In the event producing class private static MyListener observer; public static final void setObserver(MyListener observer) { MyBroadcastReceiver.observer = observer; } In the listener (in onCreate()) MyBroadcastReceiver.setObserver(this);

Application Structure

In the ‘Listening’ class – In our case this is the main Activity ‘this’ is past into the ‘setObserver’ method of the BroadcastReceiver subclass if messages can be sent, there is functionality to send a message using an instance of SmsManager – e.g. this method might be tied to a button via onClick if messages can be received, there is functionality that handles the actual message – placed in TextView, stored in db, etc. – this method typically called from receiver class » can also be called from listening class if needed

Application Structure In the BroadcastReceiver subclass – static class variable with the type of the ‘Listening’ class in our case, an instance of the main Activity variable typically called ‘observer’ – static method to initialize this instance argument is an instance of the ‘Listening’ class method typically called ‘setObserver’ – onReceive method is overridden signature: public void onReceive (Context c, Intent i) SmsMessage is instantiated via createFromPdu class method in SmsMessage class Pertinent information is obtained and sent back to the observer to handle accordingly