DDMS and Intents

tibburfrogtownMobile - sans fil

14 déc. 2013 (il y a 3 années et 6 mois)

92 vue(s)

1

CSE476 Mobile Application Development


Yard. Do
ç
. Dr. Tacha Serif

tserif@cse.yeditepe.edu.tr







Department of Computer Engineering

Yeditepe University


Fall
201
3



Yeditepe University
©
2013

CSE476 Mobile Application Development

Yeditepe University

Page
2

Outline


Dalvik Debug Monitor Service (DDMS)


DDMS Functions


Intent


Implicit vs Explicit Intents


Intent Filter


How to start Activities


Intent Example



2

CSE476 Mobile Application Development

Yeditepe University

Page
3

Dalvik Debug Monitor Service (DDMS)


The

Dalvik

Debug

Monitor

Service

(DDMS)

is

a

debugging

utility

that

is

integrated

into

Eclipse

through

the

DDMS

perspective
.

The

DDMS

perspective

provides

a

number

of

useful

features

for

interacting

with

emulators

and

handsets

CSE476 Mobile Application Development

Yeditepe University

Page
4

DDMS Functions


The features of DDMS are roughly divided into
five functional areas:


Task management


File management


Emulator interaction


Logging


Screen captures

3

CSE476 Mobile Application Development

Yeditepe University

Page
5

DDMS


Managing Tasks


The top
-
left corner of the DDMS lists the emulators and handsets
currently connected.


You can select individual instances and inspect processes and threads.

CSE476 Mobile Application Development

Yeditepe University

Page
6

DDMS


File System


You can use the DDMS File Explorer to browse files and directories on the
emulator
or a device


You can copy files between the Android file system and your development
machine by using the push and pull

4

CSE476 Mobile Application Development

Yeditepe University

Page
7

DDMS
-

Simulating Calls


CSE476 Mobile Application Development

Yeditepe University

Page
8

DDMS
-

Screenshot


5

CSE476 Mobile Application Development

Yeditepe University

Page
9

Intent


An Intent object encapsulates a task request used by
the Android operating system. When the
startActivity() method is called with the Intent
parameter, the Android system matches the Intent
action with appropriate activity on the Android
system. That activity is then launched.


The Android system handles all intent resolution. An
intent can be very specific, including a request for a
specific activity to be launched, or somewhat vague,
requesting that any activity matching certain criteria
be launched.

CSE476 Mobile Application Development

Yeditepe University

Page
10

Implicit vs Explicit Intents


Android

supports

explicit

intents

and

implicit

intents
.

Explicit

intent

names

the

component,

e
.
g
.

the

Java

class

which

should

be

called
.



Implicit

intents

asked

the

system

to

perform

a

service

without

telling

the

system

which

Java

class

should

do

this

service
.

In

constructing

an

implicit

Intent

you

specify

the

action

which

should

be

performed

and

optionally

an

URI

which

should

be

used

for

this

action
.

For

example

you

could

tell

the

system

that

you

want

to

view

(action)

a

webpage

(URI)
.

By

starting

an

intent

for

this

data

the

system

would

try

to

find

an

application

which

is

registered

for

this

event,

e
.
g
.

a

browser
.

You

can

add

more

data

to

the

Intent

by

adding

"extras"

to

the

Intent
.

These

are

key/value

pairs
.




To

get

the

Intent

information

in

the

called

Activity

use

the

method

getIntent()
.

If

the

Activity

was

called

via

an

implicit

Intent

you

can

receive

the

data

and

url

from

this

Intent

via

getAction(),

getData()

and

getExtras()
.

6

CSE476 Mobile Application Development

Yeditepe University

Page
11

Intent Filter


The

Android

system

will

determine

suitable

applications

for

an

implicit

intent

and

if

several

applications

exists

offer

the

user

the

choice

to

open

one
.

The

determination

is

based

on

intent

filters,

e
.
g
.

the

class

"android
.
content
.
IntentFilter"
.

Intent

filters

are

typically

defined

via

the

"AndroidManifest
.
xml"

file
.



To

react

to

a

certain

implicit

intent

an

application

component

must

register

itself

via

an

IntentFilter

in

the

"AndroidManifest
.
xml"

to

this

event
.

If

a

component

does

not

define

intent

filters

it

can

only

be

called

by

explicit

intents
.


CSE476 Mobile Application Development

Yeditepe University

Page
12

How to start activities


To

start

an

activity

use

the

method

startActivity(Intent)

if

you

do

not

need

a

return

value

from

the

called

activity
.



If

you

need

some

information

from

the

called

activity

use

the

method

startActivityForResult()
.

Once

the

called

Activity

is

finished

the

method

onActivityResult()

in

the

calling

activity

will

be

called
.

If

you

use

startActivityForResult()

then

the

activity

which

is

started

is

considered

a

"Sub
-
Activity"
.



7

CSE476 Mobile Application Development

Yeditepe University

Page
13

Intent Example
-

Layout


<?xml version=
"1.0"

encoding=
"utf
-
8"
?>

<LinearLayout xmlns:android=
"http://schemas.android.com/apk/res/android"

android:orientation=
"vertical"

android:layout_width=
"fill_parent"

android:layout_height=
"fill_parent"

>

<Button android:id=
"@+id/Button01"

android:layout_width=
"wrap_content"

android:layout_height=
"wrap_content"

android:text=
"Call browser"

android:onClick=
"callIntent"
></Button>

<Button android:id=
"@+id/Button02"

android:layout_width=
"wrap_content"

android:layout_height=
"wrap_content"

android:text=
"Call Someone"

android:width=
"100px"

android:onClick=
"callIntent"
></Button>

<Button android:id=
"@+id/Button03"

android:layout_width=
"wrap_content"

android:layout_height=
"wrap_content"

android:text=
"Dial"

android:width=
"100px"

android:onClick=
"callIntent"
></Button>

<Button android:id=
"@+id/Button04"

android:layout_width=
"wrap_content"

android:layout_height=
"wrap_content"

android:text=
"Show Map"

android:width=
"100px"

android:onClick=
"callIntent"
></Button>


<Button android:id=
"@+id/Button05"

android:layout_width=
"wrap_content"

android:layout_height=
"wrap_content"

android:text=
"Search on Map"

android:width=
"100px"

android:onClick=
"callIntent"
></Button>


<Button android:id=
"@+id/Button06"

android:layout_width=
"wrap_content"

android:layout_height=
"wrap_content"

android:text=
"Take picture"

android:width=
"100px"

android:onClick=
"callIntent"
></Button>

<Button android:id=
"@+id/Button07"

android:layout_width=
"wrap_content"

android:layout_height=
"wrap_content"

android:text=
"Show contacts"

android:width=
"100px"

android:onClick=
"callIntent"
></Button>

<Button android:id=
"@+id/Button08"

android:layout_width=
"wrap_content"

android:layout_height=
"wrap_content"

android:text=
"Edit first contact"

android:width=
"100px"

android:onClick=
"callIntent"
></Button>


</LinearLayout>

CSE476 Mobile Application Development

Yeditepe University

Page
14

AndroidManifest.xml

<?xml version="1.0" encoding="utf
-
8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package=“
com.example
" android:versionCode="1" android:versionName="1.0">


<application android:icon="@drawable/icon" android:label="@string/app_name">


<activity android:name=".CallIntents" android:label="@string/app_name">



<intent
-
filter> <action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />

</intent
-
filter> </activity>

</application>


<uses
-
sdk android:minSdkVersion="9" />


<uses
-
permission android:name="android.permission.CALL_PRIVILEGED"></uses
-
permission>

<uses
-
permission android:name="android.permission.CALL_PHONE"></uses
-
permission>

<uses
-
permission android:name="android.permission.INTERNET"></uses
-
permission>

<uses
-
permission android:name="android.permission.CAMERA"></uses
-
permission>

<uses
-
permission android:name="android.permission.READ_CONTACTS"></uses
-
permission>

</manifest>

8

CSE476 Mobile Application Development

Yeditepe University

Page
15

CallIntents.java

package
com.exaple
;


import android.app.Activity;

import android.content.Intent;

import android.net.Uri;

import android.os.Bundle;

import android.view.View;

import android.widget.Toast;


public class CallIntends extends Activity

{ /** Called when the activity is first created. */

@Override

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);


setContentView(R.layout.main); }



public void callIntent(View view)

{ Intent intent = null;


switch (view.getId()) {

case R.id.Button01: intent = new Intent(Intent.ACTION_VIEW,
Uri.parse("http://
www.yeditepe.edu.tr
"));

startActivity(intent);

break;

CSE476 Mobile Application Development

Yeditepe University

Page
16

CallIntents.java

case R.id.Button02:


intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:(+
90
)
2125780470
"));
startActivity(intent);


break;

case R.id.Button03:


intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:(+49)12345789"));
startActivity(intent);


break;

case R.id.Button04: intent = new Intent(Intent.ACTION_VIEW,
Uri.parse("geo:50.123,7.1434?z=19"));


startActivity(intent);

b
reak;

case R.id.Button05:


intent = new Intent(Intent.ACTION_VIEW, Uri.parse("geo:0,0?q=query"));
startActivity(intent);


break;

case R.id.Button06:


intent = new Intent("android.media.action.IMAGE_CAPTURE");
startActivityForResult(intent, 0);


break;

case R.id.Button07:


intent = new Intent(Intent.ACTION_VIEW, Uri.parse("content://contacts/people/"));
startActivity(intent);


break;

9

CSE476 Mobile Application Development

Yeditepe University

Page
17

CallIntents.java

case R.id.Button08:


intent = new Intent(Intent.ACTION_EDIT, Uri.parse("content://contacts/people/1"));
startActivity(intent);


break;

default:

break; }

}

@Override


public void onActivityResult(int requestCode, int resultCode, Intent data)

{ if (resultCode == Activity.RESULT_OK && requestCode == 0) {

String result = data.toURI(); Toast.makeText(this, result, Toast.LENGTH_LONG); }


}

}