Professional Documents
Culture Documents
Bài 5 - Intent PDF
Bài 5 - Intent PDF
H Ch Minh
TRUNG TM TIN HC
Lp trnh Android
Bi 5. Intent
Ngnh Mng & Thit b di ng
2014
Ni dung
1. Khi nim v Intent
C ch hot ng
Cc dng Intent
Xy dng Intent
Truy xut Intent
Gi v Phn hi Intent trong Activity
2. Intent Filter
1.1 C ch hot ng
Intent c s dng truyn ti thng ip, yu cu mt hnh
phn sau:
Component: tn thnh phn nhn v x l Intent
Action: hnh ng yu cu thc thi
Data: d liu yu cu nhn v x l
Khai bo:
Intent intent = new Intent(this, <Component>);
V d: khi ng Activity c tn SecondActivity t MainActivity
Intent intent = new Intent(MainActivty.this, SecondActivity.class);
startActivity(intent);
Khai bo:
Intent intent = new Intent(<Action>);
V d: khi ng Activity c th thc hin ACTION_VIEW.
Intent intent = new Intent(Intent.ACTION_VIEW);
startActivity(intent);
ACTION_VIEW
ACTION_DIAL
ACTION_CALL
ACTION_EDIT
ACTION_DELETE
ACTION_SEND
ACTION_SENDTO
type
scheme + authority + path
Data c th ch nh thng qua ba phng thc:
setData
setType
setDataAndType
V d: thc hin cuc gi thng qua d liu s in thoi
Intent callPhone = new Intent(Intent.ACTION_CALL);
callPhone.setData(Uri.parse(tel:01234-56789));
startActivity(callPhone);
Lp trnh Android (2014) Bi 5. Intent
10
11
12
13
14
SendActivity
setResult(intent)
requestCode
ReceiveActivity
resultCode
onActivityResult(intent)
15
Ni dung
1. Khi nim v Intent
2. Intent Filter
M t
Qui tc thit lp
Xy dng IntentFilter
16
2.1 M t
Thc hin m t cu trc Intent, cho php thc hin ch nhn cc
Action
Data (type, scheme, authority & path)
Category
17
18
IntentFilter()
IntentFilter(String Action)
IntentFilter(String Action, URI data)
IntentFilter(IntentFilter o)
<action/>
<data/>
<category/>
19
Cc thuc tnh:
<action android:name=string />
Trong :
V d khai bo:
<action android:name=android.intent.action.MAIN />
<action android:name=com.htsi.t3h.action.ShowImage />
20
Cc thuc tnh:
<data android:scheme="string"
android:host="string"
android:port="string"
android:path="string"
android:pathPattern="string"
android:pathPrefix="string"
android:mimeType="string" />
V d khai bo:
<data android:scheme=http android:mimeType=video/mpeg />
<data android:mineType=image/* />
<data android:mineType=*/* />
21
Cc thuc tnh:
<category android:name=string />
Trong :
V d khai bo:
<category android:name=android.intent.category.DEFAULT />
<category android:name=android.intent.category.LAUNCHER />
22
Tho lun
23