lecture#06
TRANSCRIPT
![Page 1: Lecture#06](https://reader035.vdocument.in/reader035/viewer/2022081413/547ac667b479595e098b4b94/html5/thumbnails/1.jpg)
Mobile ComputingIntents, Intent-Filters
1
Lecture#06
![Page 2: Lecture#06](https://reader035.vdocument.in/reader035/viewer/2022081413/547ac667b479595e098b4b94/html5/thumbnails/2.jpg)
Lecture Contents
IntentsIntent-FiltersLinkifyInent-ResolutionResponding to Intents
2
![Page 3: Lecture#06](https://reader035.vdocument.in/reader035/viewer/2022081413/547ac667b479595e098b4b94/html5/thumbnails/3.jpg)
Intents
Message passing mechanism used within application or among applications:
Majorly used for1. Declare your intention to start an
activity / service with some piece of data2. Broadcast that an event has occurred3. Explicitly start an activity / service
3
![Page 4: Lecture#06](https://reader035.vdocument.in/reader035/viewer/2022081413/547ac667b479595e098b4b94/html5/thumbnails/4.jpg)
Full Device as Interconnected System
Enhance interaction among applications on a device One application can register for any global
event e.g. incoming call, sms received, sms sent, internet connection status changed etc
Any application registered for a global event can respond to event without caring ‘where’ that event occurred within the system
Intents can broadcast message among system’s applications (event driven system can be created)
4
![Page 5: Lecture#06](https://reader035.vdocument.in/reader035/viewer/2022081413/547ac667b479595e098b4b94/html5/thumbnails/5.jpg)
Start ActivityIntent open = new Intent(MyActivity.this,
OtherActivity.class);startActivity(open);
5
1. No connection among newly opened activity and current activity
2. For feedback from newly opened activity one should use startActivityForResult(Inent) method instead
![Page 6: Lecture#06](https://reader035.vdocument.in/reader035/viewer/2022081413/547ac667b479595e098b4b94/html5/thumbnails/6.jpg)
Implicit IntentAn activity can announce that some event has
occurred and some component should respond to this event (mentioning some data for said purpose)
No need to explicitly mention which component (activity/service) should respond to this event
Examples:a) Call to given number
i. Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:555-2368"));
b) Open given URL in web browseri. Intent viewIntent = new
Intent("android.intent.action.VIEW", Uri.parse("http://www.google.com"));
c) Send SMS to provided number
6
![Page 7: Lecture#06](https://reader035.vdocument.in/reader035/viewer/2022081413/547ac667b479595e098b4b94/html5/thumbnails/7.jpg)
Sub Activity & ResultsUri uri = Uri.parse("content://contacts/people");Intent intent = new Intent(Intent.ACTION_PICK, uri);startActivityForResult(intent, PICK_CONTACT_SUBACTIVITY);
7
Bundle stats = new Bundle();stats.putString(“channel",“Banking"");stats.putString(“level”, “high");stats.putString(“code", “success");setResult(0, Activity.RESULT_OK, stats);finish();
![Page 8: Lecture#06](https://reader035.vdocument.in/reader035/viewer/2022081413/547ac667b479595e098b4b94/html5/thumbnails/8.jpg)
Start Implicit for ResultUri uri = Uri.parse("content://contacts/people");//Uri for phone contacts
8
startActivityForResult(intent, PICK_CONTACT_SUBACTIVITY);
//Starting activity and waiting for result
Intent intent = new Intent(Intent.ACTION_PICK, uri);//Intent just mentioning the action
![Page 9: Lecture#06](https://reader035.vdocument.in/reader035/viewer/2022081413/547ac667b479595e098b4b94/html5/thumbnails/9.jpg)
Native Android ActionsACTION_ANSWER
Handles incoming call
ACTION_CALL Calls through default dialer
ACTION_DELETE Lets you delete the content
ACTION_DIAL Opens default dialer with number
ACTION_EDIT Let you edit the data
ACTION_PICKLets you pick the item
9
![Page 10: Lecture#06](https://reader035.vdocument.in/reader035/viewer/2022081413/547ac667b479595e098b4b94/html5/thumbnails/10.jpg)
LinkifyAutomatic linking of special data with applicationsTextView textView = …….;Linkify.addLinks(textView, Linkify.WEB_URLS);
10
Other data types:::1. Linkify.EMAIL_ADDRESSES2. Linkify.WEB_URLS3. Linkify.MAP_ADDRESSES4. Linkify.PHONE_NUMBERS5. Linkify.ALL
![Page 11: Lecture#06](https://reader035.vdocument.in/reader035/viewer/2022081413/547ac667b479595e098b4b94/html5/thumbnails/11.jpg)
Linkify & XML<TextViewAndroid:layout_width=“fill_parent”Android:layout_height=“fill_parent”Android:text=“@string/linkify_string”Android:autoLink=“phone|email”/>
11
![Page 12: Lecture#06](https://reader035.vdocument.in/reader035/viewer/2022081413/547ac667b479595e098b4b94/html5/thumbnails/12.jpg)
Intent FilterAn intent is an expression of interest for an
action to be performed (a request for something to be happened)
Intent-Filter is an expression of interest for response against some event or to handle some data-type
12
![Page 13: Lecture#06](https://reader035.vdocument.in/reader035/viewer/2022081413/547ac667b479595e098b4b94/html5/thumbnails/13.jpg)
Intent-Filter
Using intent-filter an application tells android that it can serve against particular applications coming from
1. Same application2. Native phone applications3. Third party applications
13
![Page 14: Lecture#06](https://reader035.vdocument.in/reader035/viewer/2022081413/547ac667b479595e098b4b94/html5/thumbnails/14.jpg)
Manifest/intent-filter<intent-filter><action android:name="android.intent.action.MAIN" /><category
android:name="android.intent.category.LAUNCHER" /></intent-filter>
14
Action::::1. Describes what action needs to be served. 2. android:name to describe name of action3. Preferably use java package naming conventionsCategory::::4. Describes under what circumstances action should be
served5. Each intent-filter can describe multiple category tags6. One can specify his own category values7. Using predefined category values is also possible
![Page 15: Lecture#06](https://reader035.vdocument.in/reader035/viewer/2022081413/547ac667b479595e098b4b94/html5/thumbnails/15.jpg)
Manifest/intent-filter
15
Data:::::One can specify type of data your application can handle toMultiple data types for one application is also possibleList of supported data types
1. android:host (valid host name e.g. com.google)2. android:mimetype (<type
android:value=“vnd.android.Cursor.dir/*”/>)3. android:path (valid path)4. android:port (valid port for specified host)5. android:scheme (requires particular scheme http:// or
content://)
![Page 16: Lecture#06](https://reader035.vdocument.in/reader035/viewer/2022081413/547ac667b479595e098b4b94/html5/thumbnails/16.jpg)
Intent-Filter
<activity><intent-filter>
<action /> <category /> <data /> </intent-filter> <meta-data />
</activity>
16
![Page 17: Lecture#06](https://reader035.vdocument.in/reader035/viewer/2022081413/547ac667b479595e098b4b94/html5/thumbnails/17.jpg)
Broader PictureRelationship among terms (Intent, Intent-
Filter, Broadcast ReceiverIntent is a wish that a job is to be done,
Intent-Filter is registration of an Activity for a particular data type or even for some global event (A class registering for contacts handling, A class responding to sms received).
17
![Page 18: Lecture#06](https://reader035.vdocument.in/reader035/viewer/2022081413/547ac667b479595e098b4b94/html5/thumbnails/18.jpg)
Intent-Resolution
Process of deciding which action to performed against some event is called intent resolution. In case of implicit intents it is very important to understand how android resolves intents…..
Rules for intent resolution1. All intent-filters from installed packages are
kept together2. Intnet-filters with non-match action/category
for intent to be resolved are removed from list3. Each part of intent’s data uri is matched with
intent-filter’s data tag
18
![Page 19: Lecture#06](https://reader035.vdocument.in/reader035/viewer/2022081413/547ac667b479595e098b4b94/html5/thumbnails/19.jpg)
Intent-Resolution
4. If more than one intent-filters are matched then highest priority value intent-filter serves the task
5. If still conflict exists then user may be given option to choose the application to be served for that task
19
![Page 20: Lecture#06](https://reader035.vdocument.in/reader035/viewer/2022081413/547ac667b479595e098b4b94/html5/thumbnails/20.jpg)
Response for Intent-Filter Match
When application/activity starts through an implicit intent, it needs to find out action (what to do) and data upon which action is to be appliedpublic void onCreate(Bundle bundle){super.onCreate(bundle);setContentView(R.layout.main);Intent intent = getIntent();String action = intent.getAction();Uri data = intent.getData();…….. //// Action to be done}
20
![Page 21: Lecture#06](https://reader035.vdocument.in/reader035/viewer/2022081413/547ac667b479595e098b4b94/html5/thumbnails/21.jpg)
Passing on Responsibilitypublic void onCreate(Bundle bundle){
super.onCreate(bundle);setContentView(R.layout.main);Intent intent = getIntent();if(TODAY IS SATURDAY OR SUNDAY){startNextMatchingActivity(intent);}
}
21