Cosc 5/4730 Android SMS and MMS.

Slides:



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

How to Receive GoSoloTXT Messages How to Broadcast GoSoloTXT Messages Viewing GoSoloTXT Message History What is GoSoloTXT?
Cosc 5/4730 Android Services. What is a service? From android developer web pages: Most confusion about the Service class actually revolves around what.
MESSAGING. Overview  SMS sends short text messages between mobile phones.  Supports sending both text messages and data messages  MMS (multimedia messaging.
Cosc 4/5730 Android and Blackberry Near Field Communications (NFC)
The Internet. Telnet Telnet means using your computer as a terminal. All commands you type are sent to the host computer you are connected to and executed.
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.
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.
SMS. Short Message Service – Primarily text messages between mobile phones – First one sent December 3, 1982 “Merry Christmas” – In 2008 Approximately.
How to Establish a Blog. What is a Blog A blog is a collection of informational articles/ideas intended to update a viewer on new information associated.
1. 2 LXU800 User’s Manual 1.Installation – Windows XP UI Features Introduction Data Connection & Disconnection.
This is Google Drive. It stores all the documents you have made here.
Hello Employee, Welcome to MStreamIT!
Web server and web browser It’s a take and give policy in between client and server through HTTP(Hyper Text Transport Protocol) Server takes a request.
CS378 - Mobile Computing Speech to Text, Text to Speech, Telephony.
Cosc 5/4730 Sign, convert, and install Android files on Blackberry Playbook.
Introduction Our Topic: Mobile Security Why is mobile security important?
J2EE Web Fundamentals Lesson 1 Introduction and Overview
J2ME Messaging Khanh Le. Objective  The objective of wireless messaging is to extend the networking and I/O capabilities of J2ME applications to send.
Developing Push Notifications (C2DM) for Android Vijai Co-Founder Adhish Technologies, Sweet’N’Spicy apps.
© Keren Kalif Intro to Android Development Written by Keren Kalif, Edited by Liron Blecher Contains slides from Google I/O presentation.
Chapter 5: Investigate! Lists, Arrays, and Web Browsers.
Lecturer: Ghadah Aldehim
Java Mobile Application sms,sim,mms and barcode application Presented by Ayedh(SIM and MMS) Asad(SMS and Barcode Application)
Mobile Computing Lecture#08 IntentFilters & BroadcastReceivers.
Google Cloud Messaging for Android (GCM) is a free service that helps developers send data from servers to their Android.
Android Boot Camp for Developers Using Java, Comprehensive: A Guide to Creating Your First Android Apps Chapter 5: Investigate! Android Lists, Arrays,
Cosc 5/4730 Introduction: Threads, Android Activities, and MVC.
Cosc 5/4730 Android Content Providers and Intents.
Data Storage: Part 4 (Content Providers). Content Providers Content providers allow the sharing of data between applications. Inter-process communication.
Integrating with Android Services. Introduction  Android has numerous built-in functionality that can be called from within your applications  SMS/MMS.
Cosc 5/4730 Broadcast Receiver. Broadcast receiver A broadcast receiver (short receiver) – is an Android component which allows you to register for system.
DUE Hello World on the Android Platform.
16 Services and Broadcast Receivers CSNB544 Mobile Application Development Thanks to Utexas Austin.
The Internet 8th Edition Tutorial 2 Basic Communication on the Internet: .
Passing Other Objects Strings are called immutable which means that once a String object stores a value, it never changes –recall when we passed a message.
BY N.SUDHEER KUMAR E.C.E BY N.SUDHEER KUMAR E.C.E.
Lecture 8 – Cookies & Sessions SFDV3011 – Advanced Web Development 1.
GEMVC. The Setup Folders Views Value Objects (VOs) Custom Events Service CFCs Controller Model Application Main MXML.
Microsoft Office Outlook 2013 Microsoft Office Outlook 2013 Courseware # 3252 Lesson 6: Organizing Information.
The Post Office Module. Manhattan’s Post Office Module is a private system open only to members of your virtual classroom.
Telephony and sms API’S. Objective Telephony ➤ Initiating phone calls ➤ Reading the phone, network, data connectivity, and SIM states ➤ Monitoring changes.
Getting Started with Chatter Nina Jameson Senior Business Analyst, ISU-ITS (office)
1 UNIT 13 The World Wide Web Lecturer: Kholood Baselm.
©SoftMooreSlide 1 Introduction to HTML: Forms ©SoftMooreSlide 2 Forms Forms provide a simple mechanism for collecting user data and submitting it to.
PROG Mobile Java Application Development PROG Mobile Java Application Development Data Storage, Continued.
Introduction to Your OUSD and other district technology applications Leah Jensen, Instructional Technologist (510) (office), (510)
Cosc 5/4730 Android Maps v2 Blackberry Maps. Android.
Cosc 5/4735 Voice Actions Voice Interactions (API 23+)
How Information Flows via the Internet By: Lee Farrell.
1 Network Communications A Brief Introduction. 2 Network Communications.
1 UNIT 13 The World Wide Web. Introduction 2 The World Wide Web: ▫ Commonly referred to as WWW or the Web. ▫ Is a service on the Internet. It consists.
Mobile Software Development for Android - I397 IT COLLEGE, ANDRES KÄVER, WEB:
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 and IOS Permissions Why are they here and what do they want from me?
Messaging and Networking. Objectives Send SMS messages using the Messaging app Send SMS messages programmatically from within your app Receive and consume.
Chapter 5: Investigate! Lists, Arrays, and Web Browsers.
Cosc 4735 Nougat API 24+ additions.
Getting Started with Chatter
Messaging Unit-4.
CIS 470 Mobile App Development
Android Notifications (Part 2) Plus Alarms and BroadcastReceivers
Getting Started with UCSF Chatter
Programming in JavaScript
CIS 470 Mobile App Development
Programming in JavaScript
Android Developer Fundamentals V2 Lesson 5
Programming in JavaScript
Lecture 2: Android Concepts
Presentation transcript:

Cosc 5/4730 Android SMS and MMS

Introduction Wireless messaging protocols predate JavaME, Android, Blackberry IP over cellular networks (most cell phone networks) Developed for Pagers and now used for call control. Wireless Messaging services Major: SMS, Cell Broadcast (SMS-CB), MMS

SMS Short message service (ie texting) Developed in 1985 by Global System for mobile (GSM) All major terrestrial cellular network support it in some form. 160 characters compressed into 140 bytes There is a binary format as well (not MMS) routed by SMS center (SMSC) No guarantee of delivery. Can be address to a port (on a device), so different applications can receive the sms message. CDMA (most north American carriers) may not use port numbers

MMS Multimedia Messaging Service Works on top of a number of wireless protocols SMS or TCP/IP Uses same ideas as email message subject, body, multiple messages parts multiple receipts as well. Uses MMS Center to route messages. Problems, not everyone device supports it Carriers can't agree on MMS, so may not route between Cell Carriers either.

mms message

SMB-CB Short Message Service Cell Broadcast Very new, not generally available. May never be available to general public. it's a point to area (1 to many) protocol Allows you send a message to an area (such a geographic region or city) Weather service, alerts, that sort of thing. (advertizing?) message is 82 bytes, text or binary can be concatenated a mechanism to deliver longer messages.

As a side note. Standard SMS message accept a port number as well as a phone number. The default is port Zero. But on other devices you can use your own port number as well, so it would stay off the main sms applications. Ie a private sms message between applications. The user would never see the messages! Android does not appear to support port numbers in their sms API. But port numbers are supported in the binary method.

SMS and KitKat Android 4.4 There is a default SMS app now, which can be a third party app. And only the default SMS app can write directory to the SMS ContentProvider The other apps will fail silently. The other apps can send a sms via an intent, which is shown in this lecture. Any app can still read sms But can not delete or “alter the flow” of the sms message.

Well cover sending a sms message first Then broadcast receiver, so we can receive sms messages. We’ll come back to binary sms methods as well.

A note first Depending on the API level, an import changes because of a deprecated API 3 uses import android.telephony.gsm.SmsManager; While above, use import android.telephony.SmsManager; The change doesn't effect the code, just if the phone supports both GSM and CDMA. The source code provided, has the gsm line commented out.

emulators To send/receive sms message between 2 emulators, the "phone number" is the port number of the emulator. (normally 5554 for the first one, 5556 for the second) remember you need to get the application on both emulators too. You can also send to the emulator you on by using it’s number, so you don’t need two. Test with the messaging app, before you test your code to make sure everything is working. Or use ddms to send sms messages.

Sending a Text message We get the static method of an SmsManager with getDefault() We then send the SMS message with PendingIntent PendingIntenet object is used to identify a target to invoke at a later time. Can be used to display another activity after we send the message, but in our case, we just point to the same activity.

Sending a Text message (2) private void sendSMS(String phoneNumber, String message) { PendingIntent pi = PendingIntent.getActivity(this, 0, new Intent(this, smsDemo.class), 0); SmsManager sms = SmsManager.getDefault(); sms.sendTextMessage(phoneNumber, null, message, pi, null); } Where phoneNumber has the phone number to send to and message is the sms message.

Sending a Text message (3) If we need to monitor the status of the SMS message sending process Was there a failure or did the message actually go out. you can actually use two PendingIntent objects together with two BroadcastReceiver objects See the Android smsDemo code example.

Receiving sms texts We extend a broadcast receiver public class SmsReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { } Intent Tells you what it is, via the get getAction() method. The SMS message is contained and attached to the Intent object via a Bundle object. The messages are stored in an Object array in the PDU format. To extract each message, you use the static createFromPdu() method from the SmsMessage class.

Receiving an sms message To receiving incoming SMS messages use a BroadcastReceiver object. For the code example, I use the receiver tag in the AndroidManifest.xml file. private static final String ACTION = "android.provider.Telephony.SMS_RECEIVED"; public void onReceive(Context context, Intent intent) { if(intent.getAction().equals(ACTION)){ //---get the SMS message passed in-- }

SmsMessage First get the SMS message from the bundle Bundle bundle = intent.getExtras(); Object[] pdus = (Object[]) bundle.get("pdus"); SmsMessage[] msgs = new SmsMessage[pdus.length]; now pull the message(s) out. for (int i=0; i<msgs.length; i++){ msgs[i] = SmsMessage.createFromPdu((byte[])pdus[i]); } msgs[i].getMessageBody().toString() returns the message msgs[i].getOriginatingAddress() has the from address

AndroidManifest.xml We need permissions to send and receive sms message with our app's. <uses-permission android:name="android.permission.SEND_SMS"/> <uses-permission android:name="android.permission.RECEIVE_SMS"/> To setup a receiver for the sms, will also need a tell the OS to send sms messages to the app. <receiver android:name=".SMSRecv"> <intent-filter> <action android:name="android.provider.Telephony.SMS_RECEIVED"/> </intent-filter> </receiver> Where SMSRecv is our class this is to receive the sms and this is a static method so once installed, it will receive all sms messages.

AndroidManifest.xml (2) <manifest package=“edu.cosc4730.smsdemo" … > <uses-permission android:name="android.permission.SEND_SMS"/> <uses-permission android:name="android.permission.RECEIVE_SMS"/> <application … > <activity android:name=".smsDemo" … > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <receiver android:name=".SMSRecv"> <action android:name="android.provider.Telephony.SMS_RECEIVED"/> </receiver> </application> </manifest>

Max length Text message can be 160 characters. If it’s longer then… There is a function named divideMessage(string), which will break a message longer then 160 into parts, then you can send it with sendMultipartTextMessage like this: ArrayList<String> messagelist = sms.divideMessage(message); sms.sendMultipartTextMessage(phonenumber, null, messagelist, null, null);

SMS folders The sms folders are dealt with via contentproviders provided. First you need use-permissions: android.permission.READ_SMS Short listing All: content://sms/all Inbox: content://sms/inbox Sent: content://sms/sent Draft: content://sms/draft Outbox: content://sms/outbox Failed: content://sms/failed Queued: content://sms/queued Undelivered: content://sms/undelivered Conversations: content://sms/conversations Since MMS and SMS are combined in android content://mms-sms/conversations See Chapter 9 of Android Pro book for more info.

Binary and port numbers We can use sendDataMessage, sendDataMessage (String destinationAddress, String scAddress, short destinationPort, byte[] data, PendingIntent sentIntent, PendingIntent deliveryIntent) scAddress is the service center address or null to use the current default SMSC. So we can sendDataMessage(phonenumber, null, (short) PortNumber, data, null, null) Where data is a byte[] array.

Binary and port numbers (2) Example: int MAX_SMS_MESSAGE_LENGTH = 160; int SMS_PORT = 8091; SmsManager manager = SmsManager.getDefault(); byte[] data = new byte[message.length()]; for(int index=0; index<message.length() && index < MAX_SMS_MESSAGE_LENGTH; ++index){ data[index] = (byte)message.charAt(index); } manager.sendDataMessage(phonenumber, null, (short) SMS_PORT, data,null, null);

Receiving binary The receiver is just the same, except that you need to convert binary to data. SmsMessage[] msgs = new SmsMessage[ pdus.length]; msgs[i] = SmsMessage.createFromPdu((byte[]) pdus[i]); byte[] data = msgs[i].getUserData(); for(int index=0; index<data.length; ++index) { info += Character.toString((char)data[index]); }

Receiving binary (2) The difference is in the manifest <receiver android:name=".BinarySMSReceiver"> <intent-filter> <action android:name="android.intent.action.DATA_SMS_RECEIVED"/> <data android:port="8091"/> <data android:scheme="sms"/> </intent-filter> </receiver>

Lastly: Binary, port number In testing, there were problems. Some it just didn’t work. Don’t know why. The binary receiver didn’t always get the message, only the messeger app got it, which displayed the “binary data”. The emulators sort of worked, but you really need to phones to test with.

Android MMS 4.3 and below It’s possible with hidden APIs But there is ZERO documentation on android's development site (at least using their search), code on the web, nor in any android book I have either. We can do this using an intent though, which is the next slide. The user will have to hit the send button in the messager app. These maybe help, but no complete answer: http://stackoverflow.com/questions/6798730/android-mms-example http://stackoverflow.com/questions/1914456/android-sdk-mms http://stackoverflow.com/questions/6659957/mms-listener-for-android http://stackoverflow.com/questions/6659957/mms-listener-for-android

Intent and MMS android 4.3 and below. We create an intent that launches the messaging app with the information and the attached “picture”. Intent sendIntent = new Intent(Intent.ACTION_SEND); sendIntent.putExtra("address", PhoneNumber); sendIntent.putExtra("sms_body", "some text"); Note, find your own picture on the system and replace this one. String url = "file:///sdcard/Download/nasapic.jpg"; sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(url)); sendIntent.setType("image/jpg"); startActivity(sendIntent);

MMS 4.4+ DevBytes: Android 4.4 SMS APIs http://www.youtube.com/watch?v=mdq0R2WQssQ http://www.shinobicontrols.com/blog/posts/2014/03/11/bitesize-android-kitkat-week-4-replacing-the-default-sms-app http://stackoverflow.com/questions/21748209/receive-mms-messages-in-android-kitkat http://android-developers.blogspot.com/2013/10/getting-your-sms-apps-ready-for-kitkat.html

Reading mms messages. Ones that already on the device. Use content://mms-sms/conversations http://stackoverflow.com/questions/3012287/how-to-read-mms-data-in-android For the varying “boxes” of mms https://developer.android.com/reference/android/provider/Telephony.Mms.html

Example code SmsDemo is a simple sms send/receive Remember you need two phones or one phone and the ddms to test with smsDemo2 uses binary data and port numbers mmsDemo shows how to use an intent to “send” a picture.

References http://mobiforge.mobi/developing/story/sms-messaging-android http://blog.bruary.net/2009/06/android-sms-handling.html http://stackoverflow.com/questions/990558/android-broadcast-receiver-for-sent-sms-messages http://developer.android.com/intl/zh-CN/reference/android/telephony/SmsManager.html http://stackoverflow.com/questions/2726976/how-to-receive-text-sms-to-specific-port

Q A &