Intents and Intent Filters.  Intents are data structures that specify  Operations to be performed  Events that have occurred  Broadcast by one component.

Slides:



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

Programming with Android: Activities and Intents Luca Bedogni Marco Di Felice Dipartimento di Scienze dell’Informazione Università di Bologna.
Programming with Android: Activities and Intents Luca Bedogni Marco Di Felice Dipartimento di Informatica – Scienza e Ingegneria Università di Bologna.
Intents.
Manifest File, Intents, and Multiple Activities. Manifest File.
The Activity Class 1.  One application component type  Provides a visual interface for a single screen  Typically supports one thing a user can do,
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.
SMS. Short Message Service – Primarily text messages between mobile phones – First one sent December 3, 1982 “Merry Christmas” – In 2008 Approximately.
Intent An Intent describes the operation to be performed. Intents are used to start an activity using either of the following methods – Context.startActivity()
Chien-Chung Shen Manifest and Activity Chien-Chung Shen
박 종 혁 컴퓨터 보안 및 운영체제 연구실 MobiSys '11 Proceedings of the 9th international conference on Mobile systems, applications,
 Understanding an activity  Starting an activity  Passing information between activities  Understanding intents  Understanding the activity lifecycle.
Software Architecture of Android Yaodong Bi, Ph.D. Department of Computing Sciences University of Scranton.
Mobile Computing Lecture#08 IntentFilters & BroadcastReceivers.
Favorite Twitter® Searches App Android How to Program © by Pearson Education, Inc. All Rights Reserved.
Android Activities 1. What are Android Activities? Activities are like windows in an Android application An application can have any number of activities.
Intent Android Club Agenda Intent class Explicit activation Implicit activation.
Erika Chin Adrienne Porter Felt Kate Greenwood David Wagner University of California Berkeley MobiSys 2011.
CS378 - Mobile Computing Intents.
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.
CS378 - Mobile Computing Intents. Allow us to use applications and components that are part of Android System – start activities – start services – deliver.
COMP 365 Android Development.  Every android application has a manifest file called AndroidManifest.xml  Found in the Project folder  Contains critical.
Networking: Part 1 (Web Content). Networking with Android Android provides A full-featured web browser based on Chromium, the open source browser engine.
Lec 03 Intents Explicit Intents Implicit Intents.
Cosc 5/4730 Android Communications Intents, callbacks, and setters.
Linking Activities using Intents How to navigate between Android Activities 1Linking Activities using Intents.
Applications with Multiple Activities. Most applications will have more than one activity. The main activity is started when the application is started.
1 Mobile Software Development Framework: Android Inter- Thread, Process Communications 10/11/2012 Y. Richard Yang.
Lec 04 Intents and Bundles Fragments. Activated by Intents Activities Services Broadcast Receivers (aka Receivers) (
Introducing Intents Intents Bind application components and navigate between them Transform device into collection of interconnected systems Creating a.
Activities and Intents Richard S. Stansbury 2015.
Intents 1 CS440. Intents  Message passing mechanism  Most common uses:  starting an Activity (open an , contact, etc.)  starting an Activity.
Android Intents Nasrullah. Using the application context You use the application context to access settings and resources shared across multiple activity.
Android and s Ken Nguyen Clayton state University 2012.
Enterprise Library Caching Application Block Peter Provost Software Design Engineer Ron Jacobs Product Manager Scott Densmore Software Design Engineer.
Activities and Intents Chapter 3 1. Objectives Explore an activity’s lifecycle Learn about saving and restoring an activity Understand intents and how.
Speech Service & client(Activity) 오지영.
Mobile Programming Lecture 4 Resources, Selection, Activities, Intents.
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.
Xamarin Android Hands On. Hands-On: Xamarin Android Ziele – Kennenlernen von Xamarin Android – Native UI –
Working with Multiple Activities. Slide 2 Introduction Working with multiple activities Putting together the AndroidManifest.xml file Creating multiple.
Messaging and Networking. Objectives Send SMS messages using the Messaging app Send SMS messages programmatically from within your app Receive and consume.
CS371m - Mobile Computing Intents 1. Allow us to use applications and components that are already part of Android System – start activities – start services.
Menus. Menus are a common user interface component in many types of applications. The options menu is the primary collection of menu items for an activity.
Android Mobile Application Development
Android Application -Architecture.
Intents and Broadcast Receivers
Android 01: Fundamentals
Android N Amanquah.
CS499 – Mobile Application Development
Programming with Android:
Broadcast receivers.
Android 5: Interacting with Other Apps
Linking Activities using Intents
Basic Activities and Intents
Lecture 3 agenda A tour of Android studio features
MAD.
CS499 – Mobile Application Development
Mobile Application Development BSCS-7 Lecture # 3
Android Programming Lecture 9
Android Programming Lecture 5
Activities and Intents
Android Topics What are Intents? Implicit Intents vs. Explicit Intents
Activities and Intents
Android Developer Fundamentals V2 Lesson 5
It is used to Start an Activity Start a Service Deliver a Broadcast
Chapter 5 Your Second Activity.
Activities, Fragments, and Intents
Presentation transcript:

Intents and Intent Filters

 Intents are data structures that specify  Operations to be performed  Events that have occurred  Broadcast by one component  Received by one or more components

 The action to be performed  Examples:

 Setting the Intent Action new Intent(Intent.ACTION_VIEW); Intent newInt = new Intent(); newInt.setAction(Intent.ACTION_VIEW);

 Data associated with the Intent  Formatted as a Uniform Resource Locator (URI)  Examples:  Data to view on a map ▪ geo:0,0?q=1600+Pennsylvania+Ave +Washington+DC  Number to dial in the phone dialer ▪ tel:

 Setting the Intent data new Intent(Intent.ACTION_VIEW, Uri.parse("tel: ")); Intent newInt = new Intent(Intent.ACTION_VIEW); newInt.setData(Uri.parse("tel: "));

 Additional information about the components that handle the intent  Examples:

 Sets the MIME type of the Intent data  E.g., “image/*”  If unspecified, Android will infer the type  Setting the mime type Intent.setType(String type) Intent.setDataAndType(Uri data, String type)

 The component to receive this intent  Setting the component Intent(Context packageContext, Class cls); Intent newInt = new Intent (); newInt.setComponent(ComponentName) ; newInt.setClass(Context, Class));

 Additional information associated with Intent  Treated as key-value pairs  Setting the Extra attribute  Comes in several forms depending on data types involved, e.g.,  setExtra(String name, char value);

 EXTRA_  addresses to send an message to Intent newInt= new Intent(Intent.ACTION_SEND); newInt.putExtra ( android.content.Intent.EXTRA_ , new

 Specify how Intent should be handled  Examples:  FLAG_ACTIVITY_NO_HISTORY ▪ Don’t put this Activity in the History stack  FLAG_DEBUG_LOG_RESOLUTION ▪ Causes extra logging information to be printed when this Intent is processed

Intent newInt= new Intent(Intent.ACTION_SEND); newInt.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);

 Intents are used to activate Activities  startActivity(Intent intent)  startActivityForResult(Intent intent, …)  The Activity to be activated can be  Named explicitly in the Intent, or  Can be determined through the intent resolution process

 HelloWorldWithLogin  Users must authenticate before viewing the “Hello, Android” message  LoginActivity  Accepts username & password  If password correct, starts HelloAndroid Activity

public class LoginScreen extends Activity { public void onCreate(Bundle savedInstanceState) { … loginButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { if (checkPassword(uname.getText(), passwd.getText())){ Intent helloAndroidIntent = new Intent(LoginScreen.this, HelloAndroid.class); startActivity(helloAndroidIntent); } } }); }

 When the Activity to be activated is not named, the system attempts to find an Activity that matches the Intent  Called Intent Resolution

 A process for matching Intents with Activities that want to receive them  Intent Filters describe which Intents an Activity can handle  Usually specified in an AndroidManifest.xml file  Intent Resolution only considers the following  Action  Data (both URI and mime data type)  Category

<intent-filter android:icon="drawable resource” android:label="string resource” android:priority="integer”iconlabelpriority... … …

 android:icon – Icon representing the activity  android:label - User-readable label for the parent component  android:priority – Priority given to the parent component when handling matching intents  Causes Android to prefer one activity over another  Higher values represent higher priorities

… <data android:host="string" android:mimeType="string" android:path="string" android:pathPattern="string" android:pathPrefix="string" android:port="string" android:scheme="string" /> …

... …

<action android:name= "android.intent.action.VIEW" />

public class CheckIntents extends Activity { … public void onCreate(Bundle savedInstanceState) { … checkButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { List acts = CheckIntents.getActivitiesForAction( CheckIntents.this, intentText.getText().toString()) // output results } }); }

public static List getActivitiesForAction( Context context,String action) { final PackageManager packageManager = context.getPackageManager(); final Intent intent = new Intent(action); final List list = packageManager.queryIntentActivities(intent, 0); final List acts = new ArrayList (); for (ResolveInfo ri : list) { acts.add(ri.activityInfo.name); } return acts; } …