mobile app programming practice - skkuarcs.skku.edu/pmwiki/uploads/courses/swpractice3/05... ·...
TRANSCRIPT
Mobile Programming Practice
▪ Explicit intent
▪ Implicit intent
▪ Intent filter
▪ Lab#4
▪ PA #1
1
Prof. Hwansoo Han
T.A. Sung-in Hong
T.A. Minseop Jeong
Lecture schedule
Spring 2019 (Tuesday)
This schedule can be changed
M
A
R
C
H
5 12 19 26
IntroductionAndroid overview
& basic layoutLayout Advanced UI
A
P
R
I
L
2 9 16 23 30
Intent / filter
PA#1
Broadcast receivers
and ServicesProject proposal
MID TERM
(no exam)
Content providers
M
A
Y
7 14 21 28
Advanced concepts
(1)
APIs (1)
PA#2APIs (2) Profile
J
U
N
E
4 11 18
Intro. to the Kotlin
Project
Final
Presentation
END TERM
(no class)
2
Proposal presentation
▪ 16th Apr.
▪ ≈5 min presentation (you can change contents)
• Ex)Team members
• Idea
• Goals
• …
▪ Please upload your presentation material on i-Campus until Proposal day
3
Intent
▪ An Intent is a messaging object you can use to
request an action from another app component
▪ Three fundamental use cases:
1. Starting an activity : Context.startActivity()
2. Starting a service : Context.startService()
3. Delivering a broadcast : Context.sendBroadcast()
4
Intent types
▪ Explicit intents
• specify which application will satisfy the intent, by
supplying either the target app's package name or
a fully-qualified component class name
▪ Implicit intents
• do not name a specific component, but instead
declare a general action to perform, which allows a
component from another app to handle it
5
Primary info. of intent
▪ Component name
• The name of the component to start
• Optional, but it’s the critical piece of info. that makes an intent explicit
▪ Action
• A string that specifies the generic action to perform
• Ex) ACTION_IMAGE_CAPTURE
▪ Data
• The URI(a Uri object) that references the data to be acted on and/or the MIME type of that data.
• URI : Uniform Resource Identifier
• MIME : type/subtype (e.g. image/jpeg)
6
Primary info. of intent
▪ Category
• A string containing additional information about the
kind of component that should handle the intent
▪ Extras
• Key-value pairs that carry additional information
required to accomplish the requested action
▪ Flags
• defined in the Intent class that function as metadata
for the intent
7
Explicit intent
8
// Explicit Intent by specifying its class name
Intent i = new Intent(FirstActivity.this, SecondActivity.class);
// Starts TargetActivity
startActivity(i);
*https://www.tutorialspoint.com/android/android_intents_filters.htm
Creating explicit intent
▪ Constructor
• Public Intent(Context packageContext, class<?> cls);• packagageContext : the Context of current Activity
• cls : the class of target Activity
▪ Set parameter to Intent
• putExtra(String name, …); //key, value
// Explicit Intent by specifying its class nameIntent i = new Intent(FirstActivity.this, SecondActivity.class); // Explicit Intent by specifying its class namei.putExtra(“myData”,editText.getText().toString());startActivity(i);
9
Receiving an explicit intent
▪ public Intent getIntent();
• Get Intent object which is submitted from previous Component
▪ public bundle getExtra();
▪ public String getStringExtra() : to get String data
▪ public String getIntExtra() : to get Int data
Intent i = getIntent();
bundle extras = i.getExtras();String text = extras.getString(“myData”);OrString text = i.getStringExtra(“myData”);
10
Implicit intent
▪ An implicit intent specifies an action that can invoke
any app on the device able to perform the action.
• Using an implicit intent is useful when your app cannot perform
the action, but other apps probably can and you'd like the user to
pick which app to use.
11
*http://interviewquestionanswer.com/android-questions/what-is-an-implicit-intent
Creating implicit intent
▪ Constructor
• public Intent(String action)
• public Intent(String action, Uri, uri)
▪ Action strings for instantiating Intent is
statically defined in Intent class
Please refer APPENDIX A – LIST OF
COMMON INTENTS
12
Example of implicit intent
String query = "android";
Intent intent = new Intent(Intent.ACTION_WEB_SEARCH);
intent.putExtra(SearchManager.QUERY,query);
startActivity(intent);
13
Intent filter
▪ Define the actions which Component will
receive in AndroidManifest
14
<activityandroid:name=".MainActivity"android:label="@string/app_name"android:theme="@style/AppTheme.NoActionBar"><intent-filter>
<action android:name="android.intent.action.MAIN" /><action android:name="android.intent.action.VIEW" /><category android:name="android.intent.category.LAUNCHER" />
</intent-filter></activity>
Example of filters
15
<activity android:name="MainActivity">
<!-- This activity is the main entry, should appear in app launcher -->
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="ShareActivity">
<!-- This activity handles "SEND" actions with text data -->
<intent-filter>
<action android:name="android.intent.action.SEND"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="text/plain"/>
</intent-filter>
<!-- This activity also handles "SEND" and "SEND_MULTIPLE" with media data -->
<intent-filter>
<action android:name="android.intent.action.SEND"/>
<action android:name="android.intent.action.SEND_MULTIPLE"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="application/vnd.google.panorama360+jpg"/>
<data android:mimeType="image/*"/>
<data android:mimeType="video/*"/>
</intent-filter>
</activity>
Receiving an implicit intent
▪ public Intent getIntent();
• Get Intent object which is submitted from previous Component
▪ public bundle getExtra();
▪ public String getStringExtra() : to get String data
▪ public String getIntExtra() : to get Int data
Intent i = getIntent();
bundle extras = i.getExtras();String text = extras.getString(“myData”);OrString text = i.getStringExtra(“myData”);
16
[Lab – Practice #4]
17
▪ Create two Activities
▪ The first Activity has
• One editText to input user name
• One button to deliver user name to
next activity
▪ The second Activity has
• Welcome message with user name
• One (or more) function to invoke any
other app
• Ex) set alarm, capture a picture, send
email and etc. (excepts web_search)
• You can add any view what you need
PA#1 – To do list
▪ Implement ‘to do list’ app.
▪ Login activity
• Enter the user id and password from the user
• The password should be covered on display
• Check user id and password are matched
• User id and password were predefined in your app
▪ ToDoList activity
• Has three vertical lists, named TASK, DOING and DONE
• Each card represents “job”• includes Job name, dead line, and description
• Belonging in one of lists
• Can move to another list
• Can be deleted, added and modified
18
*Trello
PA#1 – To do list
▪ Individual programming assignment
▪ Recommend to use Android 8.1 Oreo (API level 27)
▪ Please upload your zipped project on i-Campus
▪ Due : 23:59, 18th Apr.
▪ A Chance to earn extra 10 credit :
• User familiar interface or extra functionality
▪ Late submission : 10% penalty per day, up to 5days
• 50% of the full score is the maximum, if you delay more than 5 days
▪ Submitting all PA is mandatory to earn your grade
19
APPENDIX A – LIST OF
COMMON INTENTS
https://developer.android.com/g
uide/components/intents-
common
20
Common intents
▪ Alarm clock
▪ Calendar
▪ Camera
▪ Contacts/People App
▪ File Storage
▪ Local Actions
21
▪ Maps
▪ Music or Video
▪ New Note
▪ Phone
▪ Search
▪ Settings
▪ Text Messaging
▪ Web Browser
APPENDIX B – Forcing an app
chooser
https://developer.android.com/g
uide/components/intents-
filters#ForceChooser
22