01.11.2014 Views

The AndroidManifest.xml File - 안드로이드 기술 커뮤니티 : Korea ...

The AndroidManifest.xml File - 안드로이드 기술 커뮤니티 : Korea ...

The AndroidManifest.xml File - 안드로이드 기술 커뮤니티 : Korea ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

안드로이드 애플리케이션 교육 자료 – 7<br />

AIDL and Services<br />

www.kandroid.org 운영자 : 양정수 (yangjeongsoo@gmail.com), 닉네임:들풀


9. 퍼미션(Permission)의 protectionLevel이 의미하는 바<br />

안드로이드 보안 모델에 대한 이해는 기본적으로 리눅스 기반의 프로세스들 간의 격리, 애플리케<br />

이션을 위한 고유한 사용자 ID의 부여, 애플리케이션 고유의 파일시스템, 애플리케이션에 대한 사<br />

인 구조에 기반한다. 이러한 보안 구조는 기본적인 리눅스 보안 모델과 Java의 애플리케이션 사인<br />

모델에 기초한다. 이러한 전통적 보안 모델에 추가된 안드로이드 고유의 보안 모델이 퍼미션<br />

(Permission)이다. 안드로이드는 컴포넌트들 간의 바인딩(또는 호출) 및 API 사용시 퍼미션을 적용<br />

하는 구조를 제공한다. 퍼미션은 이미 정의된 것들도 있지만, 누구나 정의하고 강제할 수 있다. 퍼<br />

미션은 안드로이드 매니페스트 파일의 permission 엘리먼트를 사용해서 정의되며, 해당 엘리먼트<br />

는 protectionLevel이라는 애트리뷰트를 가진다. protectionLevel은 normal, dangerous, signature,<br />

signatureOrSystem 중 하나의 값을 가진다. 여기에서 주목할 만한 것은 dangerous와 signature이<br />

다. 만약 컴포넌트에 강제된 permission에 대한 protectionLevel이 normal이라면 사용자의 승인을<br />

요구한다는 것이며, signature 또는 signatureOrSystem이라면 동일한 인증서로 사인된 컴포넌트<br />

들간에만 바인딩(또는 호출) 및 API 사용이 가능하다는 것이다. 더불어 안드로이드 플랫폼내에는<br />

이미 다양한 애플리케이션들과 API가 존재하며, 이와 관련되어 4개의 인증서가 디폴트로 사용되<br />

고 있다. 이것이 의미하는 바 역시 좀 더 깊숙이 고찰하는 것도 필요하다.<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

2


1. AIDL and Services


애플리케이션 개요 : 컴포넌트 생명주기<br />

Service 생명주기<br />

A service can be used in<br />

two ways:<br />

Service is<br />

started by<br />

startsService()<br />

Service is<br />

started by<br />

bindService()<br />

Context.startService()<br />

It can be started and<br />

allowed to run until<br />

someone stops it or it<br />

stops itself.<br />

onCreate()<br />

onStart()<br />

onCreate()<br />

onBind()<br />

Context.bindService()<br />

Service is<br />

running<br />

Client interacts with the service<br />

onRebind()<br />

It can be operated<br />

programmatically using<br />

an interface that it<br />

defines and exports.<br />

<strong>The</strong> service<br />

is stopped<br />

(no callback)<br />

onDestory()<br />

onUnbind()<br />

onDestory()<br />

Service is<br />

Shut down<br />

Service is<br />

Shut down<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

4


애플리케이션 개요 : Processes & Threads<br />

Remote procedure calls<br />

Android has a lightweight<br />

mechanism for remote procedure<br />

calls (RPCs) - where a method is<br />

called locally, but executed<br />

remotely (in another process), with<br />

any result returned back to the<br />

caller.<br />

defined<br />

by<br />

Android<br />

Binder<br />

class<br />

IBinder<br />

interface<br />

This entails decomposing the<br />

method call and all its attendant<br />

data to a level the operating<br />

system can understand,<br />

transmitting it from the local<br />

process and address space to the<br />

remote process and address<br />

space, and reassembling and<br />

reenacting the call there.<br />

Interface generated<br />

by the aidl tool<br />

defined<br />

by<br />

application<br />

Stub<br />

inner class<br />

class that implements<br />

the interface<br />

inner class<br />

Used by Android<br />

…<br />

used remotely<br />

(by the service)<br />

used locally<br />

(by clients of the service)<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

5


AIDL (Android Interface Definition Language)<br />

IDL <strong>File</strong><br />

idl tool<br />

Code<br />

- C<br />

- C++<br />

- Java<br />

- Perl …<br />

AIDL <strong>File</strong><br />

aidl tool<br />

Java<br />

Code<br />

aidl<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

6


AIDL (Android Interface Definition Language)<br />

Designing a Remote Interface Using AIDL<br />

Since each application runs in its own process, and you can write a service that runs in a<br />

different process from your Application's UI, sometimes you need to pass objects between<br />

processes. On the Android platform, one process can not normally access the memory of<br />

another process. So to talk, they need to decompose their objects into primitives that the<br />

operating system can understand, and "marshall" the object across that boundary for you.<br />

<strong>The</strong> code to do that marshalling is tedious to write, so we provide the AIDL tool to do it for<br />

you.<br />

AIDL (Android Interface Definition Language) is an IDL language used to generate code that<br />

enables two processes on an Android-powered device to talk using interprocess<br />

communication (IPC). If you have code in one process (for example, in an Activity) that<br />

needs to call methods on an object in another process (for example, a Service), you would<br />

use AIDL to generate code to marshall the parameters.<br />

<strong>The</strong> AIDL IPC mechanism is interface-based, similar to COM or Corba, but lighter weight. It<br />

uses a proxy class to pass values between the client and the implementation.<br />

• Implementing IPC Using AIDL<br />

• Calling an .aidl (IPC) Class<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

7


AIDL (Android Interface Definition Language)<br />

Implementing IPC Using AIDL<br />

Follow these steps to implement an IPC service using AIDL.<br />

1. Create your .aidl file - This file defines an interface (YourInterface.aidl) that defines the<br />

methods and fields available to a client.<br />

2. Add the .aidl file to your makefile - (the ADT Plugin for Eclipse manages this for you).<br />

Android includes the compiler, called AIDL, in the tools/ directory.<br />

3. Implement your interface methods - <strong>The</strong> AIDL compiler creates an interface in the Java<br />

programming language from your AIDL interface. This interface has an inner abstract<br />

class named Stub that inherits the interface (and implements a few additional methods<br />

necessary for the IPC call). You must create a class that extends YourInterface.Stub and<br />

implements the methods you declared in your .aidl file.<br />

4. Expose your interface to clients - If you're writing a service, you should extend Service<br />

and override Service.onBind(Intent) to return an instance of your class that implements<br />

your interface.<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

8


AIDL (Android Interface Definition Language)<br />

Implementing IPC Using AIDL : Creating an .aidl <strong>File</strong><br />

AIDL is a simple syntax that lets you declare an interface with one or more methods, that can<br />

take parameters and return values. <strong>The</strong>se parameters and return values can be of any type,<br />

even other AIDL-generated interfaces. However, it is important to note that you must import all<br />

non-built-in in types, even if they are defined in the same package as your interface. Here are the<br />

data types that AIDL can support:<br />

• Primitive Java programming language types (int, boolean, etc) - No import statement is needed.<br />

• One of the following classes (no import statements needed):<br />

• String<br />

• List - All elements in the List must be one of the types in this list, including other AIDL-generated<br />

interfaces and parcelables. List may optionally be used as a "generic" class (e.g. List). <strong>The</strong><br />

actual concrete class that the other side will receive will always be an ArrayList, although the method will<br />

be generated to use the List interface.<br />

• Map - All elements in the Map must be of one of the types in this list, including other AIDL-generated<br />

interfaces and parcelables. Generic maps, (e.g. of the form Map are not supported. <strong>The</strong><br />

actual concrete class that the other side will receive will always be a HashMap, although the method will<br />

be generated to use the Map interface.<br />

• CharSequence - This is useful for the CharSequence types used by TextView and other widget objects.<br />

• Other AIDL-generated interfaces, which are always passed by reference. An import statement<br />

is always needed for these.<br />

• Custom classes that implement the Parcelable protocol and are passed by value. An import<br />

statement t t is always needed d for these.<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

9


AIDL (Android Interface Definition Language)<br />

Implementing IPC Using AIDL : Implementing the Interface<br />

AIDL generates an interface file for you with the same name as your .aidl file. If you are using<br />

the Eclipse plugin, AIDL will automatically be run as part of the build process (you don't need to<br />

run AIDL first and then build your project). If you are not using the plugin, you should run AIDL<br />

first.<br />

<strong>The</strong> generated interface includes an abstract inner class named Stub that declares all the<br />

methods that you declared in your .aidl file. Stub also defines a few helper methods, most<br />

notably asInterface(), which takes an IBinder (passed to a client's onServiceConnected()<br />

implementation when applicationContext.bindService() succeeds), and returns an instance of<br />

the interface used to call the IPC methods. See the section Calling an IPC Method for more<br />

details on how to make this cast.<br />

To implement your interface, extend YourInterface.Stub, and implement the methods. (You can<br />

create the .aidl file and implement the stub methods without building between--the Android<br />

build process will process .aidl files before .java files.)<br />

Here is an example of implementing an interface called IRemoteService, which exposes a single<br />

method, getPid(), using an anonymous instance:<br />

private final IRemoteService.Stub mBinder = new IRemoteService.Stub(){<br />

public int getPid(){<br />

return Process.myPid();<br />

}<br />

}<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

10


AIDL (Android Interface Definition Language)<br />

Implementing IPC Using AIDL : Exposing Your Interface to Clients<br />

Now that you've got your interface implementation, you need to expose it to clients. This is<br />

known as "publishing your service." To publish a service, inherit Service and implement<br />

Service.onBind(Intent) to return an instance of the class that implements your interface. Here's<br />

a code snippet of a service that exposes the IRemoteService interface to clients.<br />

public class RemoteService extends Service {<br />

...<br />

@Override<br />

public IBinder onBind(Intent intent) ){<br />

if (IRemoteService.class.getName().equals(intent.getAction())) { return mBinder; }<br />

if (ISecondary.class.getName().equals(intent.getAction())) { return mSecondaryBinder; }<br />

return null;<br />

}<br />

private final IRemoteService.Stub mBinder = new IRemoteService.Stub() {<br />

public void registerCallback(IRemoteServiceCallback cb) {<br />

if (cb != null) mCallbacks.register(cb);<br />

}<br />

public void unregisterCallback(IRemoteServiceCallback cb) {<br />

if (cb != null) mCallbacks.unregister(cb);<br />

}<br />

};<br />

private final ISecondary.Stub mSecondaryBinder = new ISecondary.Stub() {<br />

public int getPid() { return Process.myPid(); }<br />

public void basicTypes(int anInt, long aLong, boolean aBoolean,<br />

float aFloat, double aDouble, String aString) {<br />

}<br />

};<br />

}<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

11


AIDL (Android Interface Definition Language)<br />

Implementing IPC Using AIDL : Pass by value Parameters using Parcelables<br />

If you have a class that you would like to send from one process to another through an AIDL<br />

interface, you can do that. You must ensure that the code for your class is available to the other<br />

side of the IPC. Generally, that means that you're talking to a service that you started.<br />

<strong>The</strong>re are five parts to making a class support the Parcelable protocol:<br />

1. Make your class implement the Parcelable interface.<br />

2. Implement the method public void writeToParcel(Parcel out) that takes the current state of<br />

the object and writes it to a parcel.<br />

3. Implement the method public void readFromParcel(Parcel in) that reads the value in a<br />

parcel into your object.<br />

4. Add a static field called CREATOR to your class which is an object implementing the<br />

Parcelable.Creator interface.<br />

5. Last but not least:<br />

• If you are developing with Eclipse/ADT, follow these steps:<br />

• In the Package Explorer view, right-click on the project.<br />

• Choose Android Tools > Create Aidl preprocess file for Parcelable classes.<br />

• This will create a file called "project.aidl" in the root of the project. <strong>The</strong> file will be automatically<br />

used when compiling an aidl file that uses the parcelable classes.<br />

• If you are developing with Ant or are using a custom build process, create an aidl file that declares your<br />

parcelable class (as shown below). If you are using a custom build process, do not add the aidl file to<br />

your build. Similar to a header file in C, the aidl file isn't compiled.<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

12


AIDL (1.5 Change Feature)<br />

Implementing IPC Using AIDL : Pass by value Parameters using Parcelables<br />

If you have a class that you would like to send from one process to another through an AIDL<br />

interface, you can do that. You must ensure that the code for your class is available to the other<br />

side of the IPC. Generally, that means that you're talking to a service that you started.<br />

<strong>The</strong>re are five parts to making a class support the Parcelable protocol:<br />

1. Make your class implement the Parcelable interface.<br />

2. Implement the method public void writeToParcel(Parcel out) that takes the current state of<br />

the object and writes it to a parcel.<br />

3. Implement the method public void readFromParcel(Parcel in) that reads the value in a<br />

parcel into your object.<br />

4. Add a static field called CREATOR to your class which is an object implementing the<br />

Parcelable.Creator interface.<br />

5. Last but not least, create an aidl file that declares your parcelable class (as shown below). If<br />

you are using a custom build process, do not add the aidl file to your build. Similar to a<br />

header file in C, the aidl file isn't compiled.<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

13


AIDL (Android Interface Definition Language)<br />

Implementing IPC Using AIDL : Pass by value Parameters using Parcelables<br />

AIDL will use these methods and fields in the code it generates to marshall and unmarshall your<br />

objects.<br />

Here is an example of how the Rect class implements the Parcelable protocol.<br />

import android.os.Parcel;<br />

import android.os.Parcelable;<br />

public final class Rect implements Parcelable {<br />

public int left;<br />

public int top;<br />

public int right;<br />

public int bottom;<br />

public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {<br />

public Rect createFromParcel(Parcel in) { return new Rect(in); }<br />

};<br />

public Rect[] newArray(int size) { return new Rect[size]; }<br />

public Rect() { }<br />

private Rect(Parcel in) { readFromParcel(in); }<br />

public void writeToParcel(Parcel out) {<br />

out.writeInt(left);<br />

out.writeInt(top);<br />

out.writeInt(right);<br />

out.writeInt(bottom);<br />

}<br />

public void readFromParcel(Parcel in) {<br />

left = in.readInt();<br />

top = in.readInt();<br />

right = in.readInt();<br />

bottom = in.readInt();<br />

}<br />

}<br />

// Rect.aidl<br />

package android.graphics;<br />

// Declare Rect so AIDL can find it and knows that it<br />

implements<br />

// the parcelable protocol.<br />

parcelable Rect;<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

14


AIDL (Android Interface Definition Language)<br />

Calling an IPC Method<br />

Here are the steps a calling class should make to call your remote interface:<br />

1. Declare a variable of the interface type that your .aidl file defined.<br />

2. Implement ServiceConnection.<br />

3. Call Context.bindService(), passing in your ServiceConnection implementation.<br />

4. In your implementation of ServiceConnection.onServiceConnected(), you will receive an<br />

IBinder instance (called service). Call YourInterfaceName.Stub.asInterface((IBinder)service)<br />

to cast the returned parameter to YourInterface type.<br />

5. Call the methods that you defined on your interface. You should always trap<br />

DeadObjectException exceptions, which are thrown when the connection has broken; this<br />

will be the only exception thrown by remote methods.<br />

6. To disconnect, call Context.unbindService() with the instance of your interface.<br />

A few comments on calling an IPC service:<br />

• Objects are reference counted across processes.<br />

• You can send anonymous objects as method arguments.<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

15


AIDL (Android Interface Definition Language)<br />

public class RemoteServiceBinding extends Activity {<br />

/** <strong>The</strong> primary interface we will be calling on the service. */<br />

IRemoteService mService = null;<br />

/** Another interface we use on the service. */<br />

ISecondary mSecondaryService = null;<br />

Calling an IPC Method : Example<br />

Button mKillButton;<br />

TextView mCallbackText;<br />

private boolean mIsBound;<br />

// Standard initialization of this activity. Set up the UI, then wait for the user to poke it before doing anything.<br />

@Override<br />

protected void onCreate(Bundle savedInstanceState) {<br />

}<br />

super.onCreate(savedInstanceState);<br />

setContentView(R.layout.remote_service_binding);<br />

// Watch for button clicks.<br />

Button button = (Button)findViewById(R.id.bind);<br />

button.setOnClickListener(mBindListener);<br />

button = (Button)findViewById(R.id.unbind);<br />

button.setOnClickListener(mUnbindListener);<br />

mKillButton = (Button)findViewById(R.id.kill);<br />

mKillButton.setOnClickListener(mKillListener);<br />

mKillButton.setEnabled(false);<br />

mCallbackText = (TextView)findViewById(R.id.callback);<br />

mCallbackText.setText( setText("Not attached. ");<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

16


AIDL (Android Interface Definition Language)<br />

/**<br />

* Class for interacting with the main interface of the service.<br />

*/<br />

private ServiceConnection mConnection =newServiceConnection() {<br />

Calling an IPC Method : Example<br />

public void onServiceConnected(ComponentName className,IBinder service) {<br />

// This is called when the connection with the service has been<br />

// established, giving us the service object we can use to<br />

// interact with the service. We are communicating with our<br />

// service through an IDL interface, so get a client-side<br />

// representation of that from the raw service object.<br />

mService = IRemoteService.Stub.asInterface(service);<br />

mKillButton.setEnabled(true);<br />

mCallbackText.setText( setText("Attached Attached. ");<br />

// We want to monitor the service for as long as we are<br />

// connected to it.<br />

try {<br />

mService.registerCallback(mCallback);<br />

i C k)<br />

} catch (RemoteException e) {<br />

}<br />

// In this case the service has crashed before we could even<br />

// do anything with it; we can count on soon being<br />

// disconnected (and then reconnected if it can be restarted)<br />

// so there is no need to do anything here.<br />

}<br />

// As part of the sample, tell the user what happened.<br />

Toast.makeText(RemoteServiceBinding.this, R.string.remote_service_connected,<br />

Toast.LENGTH_SHORT).show();<br />

show();<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

17


AIDL (Android Interface Definition Language)<br />

public void onServiceDisconnected(ComponentName className) {<br />

// This is called when the connection with the service has been<br />

// unexpectedly disconnected -- that is, its process crashed.<br />

mService = null;<br />

mKillButton.setEnabled(false);<br />

mCallbackText.setText("Disconnected.");<br />

Calling an IPC Method : Example<br />

}<br />

};<br />

// As part of the sample, tell the user what happened.<br />

Toast.makeText(RemoteServiceBinding.this, R.string.remote_service_disconnected,<br />

Toast.LENGTH_SHORT).show();<br />

/**<br />

* Class for interacting with the secondary interface of the service.<br />

*/<br />

private ServiceConnection mSecondaryConnection = new ServiceConnection() {<br />

public void onServiceConnected(ComponentName className,<br />

IBinder service) ){<br />

// Connecting to a secondary interface is the same as any<br />

// other interface.<br />

mSecondaryService = ISecondary.Stub.asInterface(service);<br />

mKillButton.setEnabled(true);<br />

}<br />

public void onServiceDisconnected(ComponentName className) {<br />

mSecondaryService = null;<br />

mKillButton.setEnabled(false);<br />

}<br />

};<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

18


AIDL (Android Interface Definition Language)<br />

Calling an IPC Method : Example<br />

private OnClickListener mBindListener = new OnClickListener() {<br />

public void onClick(View v) {<br />

// Establish a couple connections with the service, binding by interface names.<br />

// This allows other applications to be installed that replace the remote service by implementing the same interface.<br />

bindService(new Intent(IRemoteService.class.getName()), mConnection, Context.BIND_AUTO_CREATE);<br />

bindService(new Intent(ISecondary.class.getName()), mSecondaryConnection, Context.BIND_AUTO_CREATE);<br />

mIsBound = true;<br />

mCallbackText.setText("Binding.");<br />

}<br />

};<br />

private OnClickListener mUnbindListener = new OnClickListener() {<br />

public void onClick(View v) {<br />

if (mIsBound) {<br />

// If we have received the service, and hence registered with it, then now is the time to unregister.<br />

if (mService != null) {<br />

try {<br />

mService.unregisterCallback(mCallback);<br />

} catch (RemoteException e) {<br />

// <strong>The</strong>re is nothing special we need to do if the service has crashed.<br />

}<br />

}<br />

}<br />

};<br />

}<br />

// Detach our existing connection.<br />

unbindService(mConnection);<br />

unbindService(mSecondaryConnection);<br />

mKillButton.setEnabled(false);<br />

mIsBound = false;<br />

mCallbackText.setText("Unbinding.");<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

19


AIDL (Android Interface Definition Language)<br />

private OnClickListener mKillListener = new OnClickListener() {<br />

Calling an IPC Method : Example<br />

public void onClick(View v) {<br />

// To kill the process hosting our service, we need to know its<br />

// PID. Conveniently our service has a call that will return<br />

// to us that information.<br />

if (mSecondaryService != null) {<br />

try {<br />

int pid = mSecondaryService.getPid();<br />

// Note that, though this API allows us to request to kill any process based on its PID, the kernel will<br />

// still impose standard d restrictions ti on which h PIDs you are actually able to kill. Typically this means only<br />

// the process running your application and any additional processes created by that app as shown here; packages<br />

// sharing a common UID will also be able to kill each other's processes.<br />

Process.killProcess(pid);<br />

mCallbackText.setText("Killed service process.");<br />

} catch (RemoteException ex) {<br />

// Recover gracefully from the process hosting the server dying.<br />

// Just for purposes of the sample, put up a notification.<br />

}<br />

};<br />

}<br />

}<br />

Toast.makeText(RemoteServiceBinding.this,<br />

this<br />

R.string.remote_call_failed,<br />

Toast.LENGTH_SHORT).show();<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

20


AIDL (Android Interface Definition Language)<br />

// ----------------------------------------------------------------------<br />

// Code showing how to deal with callbacks.<br />

// ----------------------------------------------------------------------<br />

Calling an IPC Method : Example<br />

// This implementation is used to receive callbacks from the remote service.<br />

private IRemoteServiceCallback mCallback = new IRemoteServiceCallback.Stub() {<br />

/**<br />

* This is called by the remote service regularly to tell us about<br />

* new values. Note that IPC calls are dispatched through a thread<br />

* pool running in each process, so the code executing here will<br />

* NOT be running in our main thread like most other things -- so,<br />

* to update the UI, we need to use a Handler to hop over there.<br />

*/<br />

public void valueChanged(int value) {<br />

mHandler.sendMessage(mHandler.obtainMessage(BUMP_MSG, MSG value, 0));<br />

}<br />

};<br />

private static final int BUMP_MSG = 1;<br />

private Handler mHandler = new Handler() {<br />

@Override public void handleMessage(Message msg) {<br />

switch (msg.what) {<br />

case BUMP_MSG:<br />

mCallbackText.setText("Received from service: " + msg.arg1);<br />

break;<br />

default:<br />

super.handleMessage(msg);<br />

}<br />

}<br />

}<br />

};<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

21


Parcel : Definition<br />

Container for a message (data and object references) that can be sent through an IBinder. A<br />

Parcel can contain both flattened data that will be unflattened on the other side of the IPC (using<br />

the various methods here for writing specific types, or the general Parcelable interface), and<br />

references to live IBinder objects that will result in the other side receiving a proxy IBinder<br />

connected with the original IBinder in the Parcel.<br />

Parcel is not a general-purpose serialization mechanism. This class (and the<br />

corresponding Parcelable API for placing arbitrary objects into a Parcel) is designed as a<br />

high-performance IPC transport. As such, it is not appropriate to place any Parcel data in<br />

to persistent storage: changes in the underlying implementation of any of the data in the<br />

Parcel can render older data unreadable.<br />

<strong>The</strong> bulk of the Parcel API revolves around reading and writing data of various types. <strong>The</strong>re are<br />

six major classes of such functions available.<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

22


Parcel : Primitives<br />

<strong>The</strong> most basic data functions are for writing and reading primitive data types:<br />

writeByte(byte), readByte(),<br />

writeDouble(double), readDouble(),<br />

writeFloat(float), readFloat(),<br />

writeInt(int), readInt(),<br />

writeLong(long), readLong(),<br />

writeString(String), readString().<br />

Most other data operations are built on top of these. <strong>The</strong> given data is written and read using<br />

the endianess of the host CPU.<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

23


Parcel : Primitive Arrays<br />

<strong>The</strong>re are a variety of methods for reading and writing raw arrays of primitive objects, which<br />

generally result in writing a 4-byte length followed by the primitive data items. <strong>The</strong> methods for<br />

reading can either read the data into an existing array, or create and return a new array. <strong>The</strong>se<br />

available types are:<br />

writeBooleanArray(boolean[]), readBooleanArray(boolean[]), createBooleanArray()<br />

writeByteArray(byte[]), writeByteArray(byte[], int, int), readByteArray(byte[]), createByteArray()<br />

writeCharArray(char[]), readCharArray(char[]), createCharArray()<br />

writeDoubleArray(double[]), readDoubleArray(double[]), createDoubleArray()<br />

writeFloatArray(float[]), readFloatArray(float[]), createFloatArray()<br />

writeIntArray(int[]), readIntArray(int[]), createIntArray()<br />

writeLongArray(long[]), readLongArray(long[]), createLongArray()<br />

writeStringArray(String[]), readStringArray(String[]), createStringArray().<br />

writeSparseBooleanArray(SparseBooleanArray), readSparseBooleanArray().<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

24


Parcel : Parcelables<br />

<strong>The</strong> Parcelable protocol provides an extremely efficient (but low-level) protocol for objects to<br />

write and read themselves from Parcels. You can use the direct methods<br />

writeParcelable(Parcelable, int) and readParcelable(ClassLoader) or writeParcelableArray(T[],<br />

int) and readParcelableArray(ClassLoader) to write or read. <strong>The</strong>se methods write both the class<br />

type and its data to the Parcel, allowing that class to be reconstructed from the appropriate<br />

class loader when later reading.<br />

<strong>The</strong>re are also some methods that provide a more efficient way to work with Parcelables:<br />

writeTypedArray(T[], int), writeTypedList(List), readTypedArray(T[], Parcelable.Creator) and<br />

readTypedList(List, Parcelable.Creator). <strong>The</strong>se methods do not write the class information of<br />

the original object: instead, the caller of the read function must know what type to expect and<br />

pass in the appropriate Parcelable.Creator instead to properly construct the new object and<br />

read its data. (To more efficient write and read a single Parceable object, you can directly call<br />

Parcelable.writeToParcel and Parcelable.Creator.createFromParcel yourself.)<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

25


Parcel : Bundles<br />

A special type-safe container, called Bundle, is available for key/value maps of heterogeneous<br />

values. This has many optimizations for improved performance when reading and writing data,<br />

and its type-safe API avoids difficult to debug type errors when finally marshalling the data<br />

contents into a Parcel.<br />

<strong>The</strong> methods to use are<br />

writeBundle(Bundle),<br />

readBundle(), and<br />

readBundle(ClassLoader).<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

26


Parcel : Activie Objects<br />

An unusual feature of Parcel is the ability to read and write active objects. For these objects the<br />

actual contents of the object is not written, rather a special token referencing the object is<br />

written. When reading the object back from the Parcel, you do not get a new instance of the<br />

object, but rather a handle that operates on the exact same object that was originally written.<br />

<strong>The</strong>re are two forms of active objects available.<br />

Binder objects are a core facility of Android's general cross-process communication system.<br />

<strong>The</strong> IBinder interface describes an abstract protocol with a Binder object. Any such interface<br />

can be written in to a Parcel, and upon reading you will receive either the original object<br />

implementing that interface or a special proxy implementation that communicates calls back to<br />

the original object. <strong>The</strong> methods to use are writeStrongBinder(IBinder),<br />

writeStrongInterface(IInterface), readStrongBinder(), writeBinderArray(IBinder[]),<br />

readBinderArray(IBinder[]), createBinderArray(), writeBinderList(List), readBinderList(List),<br />

createBinderArrayList().<br />

<strong>File</strong>Descriptor objects, representing raw Linux file descriptor identifiers, can be written and<br />

Parcel<strong>File</strong>Descriptor objects returned to operate on the original file descriptor. <strong>The</strong> returned file<br />

descriptor is a dup of the original file descriptor: the object and fd is different, but operating on<br />

the same underlying file stream, with the same position, etc. <strong>The</strong> methods to use are<br />

write<strong>File</strong>Descriptor(<strong>File</strong>Descriptor), read<strong>File</strong>Descriptor().<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

27


Parcel : Activie Objects (Binder)<br />

Process A<br />

Process B<br />

App A<br />

Context<br />

Binder<br />

Service B<br />

get Service<br />

service<br />

call foo(object)<br />

marshal proxy<br />

object<br />

relay to<br />

IPC threads<br />

call return<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

28


Parcel : Activie Objects (<strong>File</strong>Descriptor)<br />

protected final Parcel<strong>File</strong>Descriptor open<strong>File</strong>Helper(Uri uri, String mode) throws <strong>File</strong>NotFoundException {<br />

Cursor c = query(uri, new String[]{"_data"}, null, null, null);<br />

int count = (c != null) ? c.getCount() : 0;<br />

if (count != 1) {<br />

// If there is not exactly one result, throw an appropriate<br />

// exception.<br />

if (c != null) {<br />

cclose(); c.close();<br />

}<br />

if (count == 0) {<br />

throw new <strong>File</strong>NotFoundException("No entry for " + uri);<br />

}<br />

throw new <strong>File</strong>NotFoundException("Multiple ti lti l items at " + uri);<br />

}<br />

c.moveToFirst();<br />

int i = c.getColumnIndex("_data");<br />

(_ String path = (i >= 0 ? c.getString(i) : null);<br />

c.close();<br />

if (path == null) {<br />

throw new <strong>File</strong>NotFoundException("Column _data not found.");<br />

}<br />

}<br />

int modeBits = ContentResolver.modeToMode(uri, mode);<br />

return Parcel<strong>File</strong>Descriptor.open(new <strong>File</strong>(path), modeBits);<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

29


Parcel : Activie Objects (<strong>File</strong>Descriptor)<br />

public final OutputStream openOutputStream(Uri uri)<br />

throws <strong>File</strong>NotFoundException {<br />

return openOutputStream(uri, "w");<br />

}<br />

public final OutputStream openOutputStream(Uri uri, String mode)<br />

throws <strong>File</strong>NotFoundException {<br />

Asset<strong>File</strong>Descriptor fd = openAsset<strong>File</strong>Descriptor(uri, p ( mode);<br />

try {<br />

return fd != null ? fd.createOutputStream() : null;<br />

} catch (IOException e) {<br />

throw new <strong>File</strong>NotFoundException("Unable to create stream");<br />

}<br />

}<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

30


Parcel : Activie Objects (<strong>File</strong>Descriptor)<br />

public final Asset<strong>File</strong>Descriptor openAsset<strong>File</strong>Descriptor(Uri uri, String mode) throws <strong>File</strong>NotFoundException {<br />

String scheme = uri.getScheme();<br />

if (SCHEME_ANDROID_RESOURCE.equals(scheme)) { /* … 생략 … }<br />

else if (SCHEME_FILE.equals(scheme)) { /* … 생략 … }<br />

else {<br />

IContentProvider provider = acquireProvider(uri);<br />

if (provider == null) { /* … 생략 … */ }<br />

try {<br />

Asset<strong>File</strong>Descriptor fd = provider.openAsset<strong>File</strong>(uri, mode);<br />

if(fd == null) { /* … 생략 … */ }<br />

Parcel<strong>File</strong>Descriptor pfd = new Parcel<strong>File</strong>DescriptorInner(fd.getParcel<strong>File</strong>Descriptor(), provider);<br />

return new Asset<strong>File</strong>Descriptor(pfd, fd.getStartOffset(),fd.getDeclaredLength());<br />

getDeclaredLength());<br />

}<br />

} catch (RemoteException e) {<br />

releaseProvider(provider);<br />

throw new <strong>File</strong>NotFoundException("Dead content provider: " + uri);<br />

} catch (<strong>File</strong>NotFoundException e) {<br />

releaseProvider(provider);<br />

throw e;<br />

} catch (RuntimeException e) {<br />

releaseProvider(provider);<br />

throw e;<br />

}<br />

}<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

31


Parcel : Untyped Containers<br />

Untyped Containers<br />

A final class of methods are for writing and reading standard Java containers of arbitrary types.<br />

<strong>The</strong>se all revolve around the writeValue(Object) and readValue(ClassLoader) methods which<br />

define the types of objects allowed.<br />

<strong>The</strong> container methods are<br />

writeArray(Object[]),<br />

readArray(ClassLoader),<br />

writeList(List),<br />

readList(List, ClassLoader),<br />

readArrayList(ClassLoader),<br />

writeMap(Map),<br />

p),<br />

readMap(Map, ClassLoader),<br />

writeSparseArray(SparseArray),<br />

readSparseArray(ClassLoader).<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

32


Parcel : Rect Example<br />

import android.os.Parcel;<br />

import android.os.Parcelable;<br />

public final class Rect implements Parcelable {<br />

public int left;<br />

public int top;<br />

public int right;<br />

public int bottom;<br />

public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {<br />

public Rect createFromParcel(Parcel in) { return new Rect(in); }<br />

public Rect[] newArray(int size) { return new Rect[size]; }<br />

};<br />

public Rect() { }<br />

private Rect(Parcel in) { readFromParcel(in); }<br />

public void writeToParcel(Parcel out) {<br />

out.writeInt(left);<br />

out.writeInt(top);<br />

out.writeInt(right);<br />

out.writeInt(bottom);<br />

}<br />

}<br />

public void readFromParcel(Parcel in) {<br />

left = in.readInt();<br />

top = in.readInt();<br />

right = in.readInt();<br />

bottom = in.readInt();<br />

}<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

33


Parcel : Rect Example (Basic (Intent) → Advanced (AIDL) )<br />

Intent i = new Intent();<br />

ComponentName comp =<br />

new ComponentName("org.kandroid.testApp",<br />

pp "org.kandroid.testApp.MyNextActivity");<br />

i.setComponent(comp);<br />

Rect rect = new Rect();<br />

rect.left =1;<br />

rect.right = 2;<br />

rect.bottom = 3;<br />

rect.top = 4;<br />

i.putExtra("parcelableContent", t t t" rect);<br />

startActivity(i);<br />

Intent intent = getIntent();<br />

Rect rect<br />

= (Rect) intent.getParcelableExtra("parcelableContent");<br />

TextView tvTop = (TextView)findViewById(R.id.top);<br />

TextView tvBottom = (TextView)findViewById(R.id.bottom);<br />

TextView tvLeft = (TextView)findViewById(R.id.left);<br />

TextView tvRight =(TextView)findViewById(R (TextView)findViewById(R.id.right); id tvTop.setText(Integer.toString(rect.top));<br />

tvBottom.setText(Integer.toString(rect.bottom));<br />

tvLeft.setText(Integer.toString(rect.left));<br />

tvRight.setText(Integer.toString(rect.right));<br />

tT t(I t t i ( t i ht))<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

34


android.content.Context<br />

android.content<br />

Contains classes for accessing and publishing data on the device. It includes three main<br />

categories of APIs: the Resources for retrieving resource data associated with an application;<br />

Content Providers and ContentResolver for managing and publishing persistent data associated<br />

with an application; and the Package Manager for finding out information about the application<br />

packages installed on the device.<br />

In addition, the Context abstract class is a base API for pulling these pieces together,<br />

allowing you to access an application's resources and transfer data between applications.<br />

android.content.Context<br />

This package builds on top of the lower-level Android packages android.database, android.text,<br />

android.graphics.drawable, android.graphics, android.os, and android.util.<br />

Interface to global information about an application environment.<br />

This is an abstract class whose implementation is provided by the Android system.<br />

It allows access to application-specific resources and classes, as well as up-calls for applicationlevel<br />

operations such as launching activities, broadcasting and receiving intents, etc.<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

35


android.content.Context : Public Methods<br />

bindService<br />

…<br />

checkUriPermission<br />

clearWallpaper<br />

createPackageContext<br />

databaseList<br />

deleteDatabase<br />

delete<strong>File</strong><br />

…<br />

enforceUriPermission<br />

fileList<br />

getApplicationContext<br />

getAssets<br />

getCacheDir<br />

getClassLoader<br />

getContentResolver<br />

getDatabasePath<br />

getDir<br />

…<br />

getMainLooper<br />

getPackageManager<br />

g g<br />

getPackageName<br />

getResource<br />

getPackageName<br />

getResource<br />

getSharedPreferences<br />

getString<br />

getSystemService<br />

getText<br />

get<strong>The</strong>me<br />

getWallpaper<br />

…<br />

grantUriPermission<br />

obtainStyledAttributes<br />

open<strong>File</strong>Input<br />

open<strong>File</strong>Output<br />

openOrCreateDatabase<br />

peekWallper<br />

registerReceiver<br />

removeStickyBroadcast<br />

revokeUriPermission<br />

sendBroadcast<br />

…<br />

set<strong>The</strong>me<br />

setWallpaper<br />

startActivity<br />

startInstrumentation<br />

startService<br />

stopService<br />

unbindService<br />

unregisterReceiver<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

36


Android Start-up (Review)<br />

Zygote<br />

App. Framework<br />

• System Services<br />

• Hardware Services<br />

Dalvik VM<br />

Home<br />

Dalvik VM<br />

?<br />

Native Server<br />

• Audio Flinger<br />

• Surface Flinger<br />

daemons<br />

• usbd<br />

• adbd<br />

• debuggerd<br />

• rild<br />

Service<br />

Manager<br />

runtime<br />

Zygote<br />

libc libc libc<br />

Init<br />

Kernel<br />

Binder Driver<br />

System Server<br />

libc<br />

Home<br />

libc<br />

zygote란 애플리케이션을 빠르게 구동하기 위해서 미<br />

리 fork 되어 있는 프로세스이다.<br />

이것은 시스템에서 exec() 호출을 통해 특정 애플리케<br />

이션을 실행하고자 하기 전까지는 중립적인 상태, 즉<br />

특정 애플리케이션과 합체되지 않는 상태를 유지한다.<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

37


Android Service List : service list<br />

phone: [com.android.internal.telephony.ITelephony]<br />

hardware: [android.os.IHardwareService]<br />

iphonesubinfo: [com.android.internal.telephony.IPhoneSubInfo] battery: []<br />

simphonebook: [com.android.internal.telephony.IIccPhoneBook]<br />

i t l content: t [android.content.IContentService]<br />

t t tS i isms: [com.android.internal.telephony.ISms]<br />

account: [android.accounts.IAccountManager]<br />

appwidget: [com.android.internal.appwidget.IAppWidgetService] permission: [android.os.IPermissionController]<br />

backup: [android.backup.IBackupManager]<br />

activity.providers: []<br />

audio: [android.media.IAudioService]<br />

activity.senders: []<br />

wallpaper: [android.app.IWallpaperManager]<br />

activity.services: []<br />

checkin: [android.os.ICheckinService]<br />

activity.broadcasts: []<br />

search: [android.app.ISearchManager]<br />

cpuinfo: []<br />

location: [android.location.ILocationManager]<br />

meminfo: []<br />

devicestoragemonitor: []<br />

activity: [android.app.IActivityManager]<br />

mount: [android.os.IMountService]<br />

package: [android.content.pm.IPackageManager]<br />

notification: [android.app.INotificationManager]<br />

telephony.registry:<br />

accessibility: [android.view.accessibility.IAccessibilityManager] [com.android.internal.telephony.ITelephonyRegistry]<br />

connectivity: [android.net.IConnectivityManager]<br />

usagestats: [com.android.internal.app.IUsageStats]<br />

wifi: [android.net.wifi.IWifiManager]<br />

batteryinfo: [com.android.internal.app.IBatteryStats]<br />

netstat: [android.os.INetStatService]<br />

power: [android.os.IPowerManager]<br />

input_method: [com.android.internal.view.IInputMethodManager] entropy: []<br />

clipboard: [android.text.IClipboard]<br />

SurfaceFlinger: [android.ui.ISurfaceComposer]<br />

statusbar: [android.app.IStatusBar]<br />

media.audio_policy: [android.media.IAudioPolicyService]<br />

window: [android.view.IWindowManager]<br />

media.camera: [android.hardware.ICameraService]<br />

sensor: [android.hardware.ISensorService]<br />

media.player: [android.media.IMediaPlayerService]<br />

alarm: [android.app.IAlarmManager]<br />

app media.audio_flinger: a dio [android.media.IAudioFlinger]<br />

dioFlinger]<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

38


질의및응답<br />

Q & A<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

39


안드로이드 애플리케이션 교육 자료 – 8<br />

<strong>AndroidManifest</strong>.<strong>xml</strong><br />

www.kandroid.org 운영자 : 양정수 (yangjeongsoo@gmail.com), 닉네임:들풀


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong><br />

<strong>AndroidManifest</strong>.<strong>xml</strong><br />

Every application must have an <strong>AndroidManifest</strong>.<strong>xml</strong> file (with precisely that name) in its root<br />

directory. <strong>The</strong> manifest presents essential information about the application to the Android system,<br />

information the system must have before it can run any of the application's code. Among other<br />

things, the manifest does the following:<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

41


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong><br />

• It names the Java package for the application. <strong>The</strong> package name serves as a unique identifier for<br />

the application.<br />

• It describes the components of the application - the activities, services, broadcast receivers, and<br />

content providers that the application is composed of. It names the classes that implement each of the<br />

components and publishes their capabilities (for example, which Intent messages they can handle).<br />

<strong>The</strong>se declarations a let the Android d system know what the components are and under what conditions<br />

o they can be launched.<br />

• It determines which processes will host application components.<br />

• It declares which permissions the application must have in order to access protected parts of<br />

the API and interact with other applications.<br />

• It also declares. the permissions that others are required to have in order to interact with the<br />

application's components<br />

• It lists the Instrumentation classes that provide profiling and other information as the<br />

application is running. <strong>The</strong>se declarations are present in the manifest only while the application is<br />

being developed and tested; they're removed before the application is published.<br />

• It declares the minimum level of the Android API that the application requires.<br />

• It lists the libraries that the application must be linked against.<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

42


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong><br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

Structure of the Manifest <strong>File</strong><br />

API Level 3<br />

API Level 4<br />

<br />

<br />

<br />

<br />

<br />

t .. t <br />

<br />

<br />

.. <br />

<br />

<br />

.. <br />

<br />

<br />

API Level 4<br />

<br />

permission><br />

<br />

<br />

<br />

<br />

<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

43


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong><br />

<strong>File</strong> Conventions<br />

Elements<br />

Only the and elements are required, they each must be present<br />

and can occur only once. Most of the others can occur many times or not at all - although at<br />

least some of them must be present for the manifest to accomplish anything meaningful.<br />

If an element contains anything at all, it contains other elements. All values are set through<br />

attributes, not as character data within an element.<br />

Elements at the same level are generally not ordered.<br />

For example, , , and elements can be intermixed in any sequence.<br />

(An alias> element is the exception to this rule: It must follow the it is an<br />

alias for.)<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

44


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong><br />

<strong>File</strong> Conventions<br />

Attributes<br />

In a formal sense, all attributes are optional. However, there are some that must be specified for<br />

an element to accomplish its purpose. Use the documentation as a guide. For truly optional<br />

attributes, it mentions a default value or states what happens in the absence of a specification.<br />

Except for some attributes of the root element, all attribute names begin with an<br />

android: prefix - for example, android:alwaysRetainTaskState. Because the prefix is universal, the<br />

documentation generally omits it when referring to attributes by name.<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

45


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong><br />

Declaring class names<br />

Many elements correspond to Java objects, including elements for the application itself (the<br />

element) and its principal components - activities (), services (),<br />

broadcast receivers (), and content providers ().<br />

If you define a subclass, as you almost always would for the component classes (Activity, Service,<br />

BroadcastReceiver, and ContentProvider), the subclass is declared through a name attribute. <strong>The</strong><br />

name must include the full package designation.<br />

<br />

<br />

<br />

. . .<br />

<br />

. . .<br />

<br />

<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

46


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong><br />

However, as a shorthand, if the first character of the string is a period, the string is appended to the<br />

application's package name (as specified by the element's package attribute).<br />

<br />

<br />

<br />

. . .<br />

<br />

. . .<br />

<br />

<br />

When starting a component, Android creates an instance of the named subclass. If a subclass isn't<br />

specified, it creates an instance of the base class.<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

47


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong><br />

Multiple values<br />

If more than one value can be specified, the element is almost always repeated, rather than listing<br />

multiple values within a single element. For example, an intent filter can list several actions:<br />

<br />

<br />

<br />

<br />

. . .<br />

<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

48


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong><br />

Resource values<br />

Some attributes have values that can be displayed to users - for example, a label and an icon<br />

for an activity. <strong>The</strong> values of these attributes should be localized and therefore set from a<br />

resource or theme. Resource values are expressed in the following format,<br />

@[package:]type:name<br />

where the package name can be omitted if the resource is in the same package as the<br />

application, type is a type of resource - such as "string" or "drawable" - and name is the name<br />

that identifies the specific resource. For example:<br />

<br />

Values from a theme are expressed in a similar manner, but with an initial '?' rather than '@':<br />

?[package:]type:name<br />

String values<br />

Where an attribute value is a string, double backslashes ('\\') must be used to escape<br />

characters - for example, '\\n' foranewlineor'\\uxxxx' for a Unicode character.<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

49


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong><br />

<strong>File</strong> Features<br />

Intent Filters<br />

<strong>The</strong> core components of an application (its activities, services, and broadcast receivers) are<br />

activated by intents. An intent is a bundle of information (an Intent object) describing a desired<br />

action - including the data to be acted upon, the category of component that should perform the<br />

action, and other pertinent instructions. Android locates an appropriate component to respond to the<br />

intent, launches a new instance of the component if one is needed, and passes it the Intent object.<br />

Components advertise their capabilities - the kinds of intents they can respond to - through intent<br />

filters. Since the Android system must learn which intents a component can handle before it<br />

launches the component, intent filters are specified in the manifest as elements. A<br />

component may have any number of filters, each one describing a different capability.<br />

An intent that explicitly names a target component will activate that component; the filter doesn't<br />

play a role. But an intent that doesn't specify a target by name can activate a component only if it<br />

can pass through one of the component's filters.<br />

For information on how Intent objects are tested against intent filters, see a separate document,<br />

Intents and Intent Filters.<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

50


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong><br />

Icons and Labels<br />

A number of elements have icon and label attributes for a small icon and a text label that can<br />

be displayed to users. Some also have a description attribute for longer explanatory text that<br />

can also be shown on-screen. For example, the element has all three of these<br />

attributes, so that when the user is asked whether to grant the permission to an application that has<br />

requested it, an icon representing the permission, the name of the permission, and a description of<br />

what it entails can all be presented to the user.<br />

In every case, the icon and label set in a containing element become the default icon and<br />

label settings for all of the container's subelements. Thus, the icon and label set in the<br />

element are the default icon and label for each of the application's components.<br />

Similarly, the icon and label set for a component - for example, an element - are the<br />

default settings for each of the component's elements. If an element<br />

sets a label, but an activity and its intent filter do not, the application label is treated as the label for<br />

both the activity and the intent filter.<br />

<strong>The</strong> icon and label set for an intent filter are used to represent a component whenever the<br />

component is presented to the user as fulfilling the function advertised by the filter. For<br />

example, a filter with "android.intent.action.MAIN" and "android.intent.category.LAUNCHER"<br />

settings advertises an activity as one that initiates an application - that is, as one that should be<br />

displayed in the application launcher. <strong>The</strong> icon and label set in the filter are therefore the ones<br />

displayed in the launcher.<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

51


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong> : permission<br />

Permissions<br />

A permission is a restriction limiting access to a part of the code or to data on the device. <strong>The</strong><br />

limitation is imposed to protect critical data and code that could be misused to distort or damage the<br />

user experience.<br />

Each permission is identified ed by a unique label. Often the label indicates the action that's restricted.<br />

ed<br />

For example, here are some permissions defined by Android:<br />

android.permission.CALL_EMERGENCY_NUMBERS<br />

android.permission.READ _ OWNER_<br />

DATA<br />

android.permission.SET_WALLPAPER<br />

android.permission.DEVICE_POWER<br />

A feature can be protected by at most one permission.<br />

If an application needs access to a feature protected by a permission, it must declare that it requires<br />

that permission with a element in the manifest. <strong>The</strong>n, when the application is<br />

installed on the device, the installer determines whether or not to grant the requested<br />

permission by checking the authorities that signed the application's certificates and, in some<br />

cases, asking the user. If the permission is granted, the application is able to use the protected<br />

features. If not, its attempts to access those features will simply fail without any notification to the user.<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

52


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong> : permission<br />

> pm list permissions –s<br />

Network communication:<br />

view Wi-Fi state, create Bluetooth connections, full Internet access, view network state<br />

Your location:<br />

access extra location provider commands, fine (GPS) location,<br />

mock location sources for testing, coarse (network-based) location<br />

Your Google accounts:<br />

Android services, Google Checkout QA accounts, Google Book Search,<br />

view configured accounts, discover known accounts, access other Google services,<br />

Google Base, Google WiFi, YouTube usernames, Google Calendar,<br />

contacts data in Google accounts, Dodgeball, Google Checkout accounts,<br />

YouTube, Google Notebook, access all Google services, JotSpot, Knol, AdWords,<br />

AdSense, Android services, Blogger, Google Health, Google Spreadsheets,<br />

Google Talk, Google mail, Google Maps, Google Docs, Picasa Web Albums, Google News,<br />

Google Webmaster Tools, iGoogle accounts, Orkut, Google mobile applications,<br />

Google App Engine, Google Checkout Sandbox accounts, Google Finance, Google Groups<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

53


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong> : permission<br />

Phone calls:<br />

intercept outgoing calls, read phone state, modify phone state<br />

Development tools:<br />

limit number of running processes, make all background applications close,<br />

send Linux signals to applications, enable application debugging<br />

System tools:<br />

set preferred applications, measure application storage space, display system-level alerts,<br />

write Access Point Name settings, retrieve system internal state, uninstall shortcuts,<br />

send package removed broadcast, write subscribed feeds, modify global animation speed,<br />

automatically start at boot, change Wi-Fi state, make application always run,<br />

read system log files, restart other applications, disable keylock, send sticky broadcast,<br />

write sync settings, read sync settings, prevent phone from sleeping,<br />

expand/collapse status bar, mount and unmount filesystems, change your UI settings,<br />

reorder running applications, set wallpaper size hints, delete all application cache data,<br />

set time zone, modify global system settings, read sync statistics,<br />

retrieve running applications, set wallpaper, read subscribed feeds, install shortcuts,<br />

read/write to resources owned by diag, change network connectivity, bluetooth administration<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

54


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong> : permission<br />

Your messages:<br />

send WAP-PUSH-received broadcast, receive WAP, read Email attachments,<br />

read SMS or MMS, send SMS-received broadcast, edit SMS or MMS, receive SMS,<br />

write instant messages, read instant messages, receive MMS<br />

Services that cost you money:<br />

send SMS messages, directly call phone numbers<br />

Hardware controls:<br />

control vibrator, test hardware, take pictures, control flashlight,<br />

change your audio settings, record audio<br />

Your personal information:<br />

write contact data, read calendar data, write owner data, read contact data,<br />

read owner data, write calendar data<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

55


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong> : permission<br />

ungrouped:<br />

Send download notifications., run in factory test mode, monitor and control all<br />

application launching, delete other applications' data, Access download manager.,<br />

directly call any phone numbers, force application to close, access checkin properties,<br />

control location update notifications, read frame buffer, display unauthorized windows,<br />

Download OTA update., publish low-level services, press keys and control buttons,<br />

reset system to factory defaults, Access DRM content., disable or modify status bar,<br />

modify battery statistics, directly install applications, manage application tokens,<br />

keep from being stopped, access SurfaceFlinger,<br />

enable or disable application components, Access download data.,<br />

record what you type and actions you take, delete applications,<br />

access to passwords for Google accounts, permanently disable phone,<br />

Use system cache., modify the Google services map, force phone reboot,<br />

delete other applications' caches, automatically install system updates,<br />

change screen orientation, select Gmail or Google Mail branding, power phone on or off<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

56


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong> : permission<br />

# pm list permissions<br />

pm list permissions<br />

All Permissions:<br />

permission:android.permission.SEND_DOWNLOAD_COMPLETED_INTENTS<br />

permission:android.permission.FACTORY_TESTTEST<br />

permission:android.permission.SET_ACTIVITY_WATCHER<br />

permission:android.permission.SET_PROCESS_FOREGROUND<br />

permission:android.permission.ACCESS_SURFACE_FLINGER<br />

permission:android.permission.CHANGE p _ COMPONENT_ ENABLED_<br />

STATE<br />

permission:android.permission.ACCESS_DOWNLOAD_DATA<br />

permission:android.permission.READ_INPUT_STATE<br />

…<br />

permission:org.kandroid.helloandroid.KANDROID<br />

permission:android.permission.ACCESS_CACHE_FILESYSTEM<br />

permission:android.permission.WRITE_GSERVICES<br />

permission:android.permission.REBOOT<br />

permission:android.permission.DELETE p _ CACHE_<br />

FILES<br />

permission:android.permission.FOTA_UPDATE<br />

permission:android.permission.SET_ORIENTATION<br />

permission:com.google.android.googleapps.permission.GOOGLE_MAIL_SWITCH<br />

permission:android.permission.DEVICE p _ POWER<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

57


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong> : permission<br />

An application can also protect its own components (activities, services, broadcast receivers,<br />

and content providers) with permissions. It can employ any of the permissions defined by<br />

Android (listed in android.Manifest.permission) or declared by other applications. Or it<br />

can define its own.<br />

A new permission is declared with the element. For example, an activity could<br />

be protected as follows:<br />

<br />

<br />

. . .<br />

<br />

<br />

android:permission="com.example.project.DEBIT p p j _ ACCT"<br />

. . . ><br />

. . .<br />

<br />

<br />

. . .<br />

<br />

. . .<br />

<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

58


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong> : permission<br />

Note that, in this example, the DEBIT_ACCT permission is not only declared with the<br />

element, its use is also requested with the element. Its use<br />

must be requested in order for other components of the application to launch the protected<br />

activity, even though the protection is imposed by the application itself.<br />

If, in the same example, the permission attribute was set to a permission declared<br />

elsewhere (such as android.permission.CALL_EMERGENCY_NUMBERS, it would not have<br />

been necessary to declare it again with a element. However, it would still<br />

have been necessary to request its use with .<br />

<strong>The</strong> element declares a namespace for a group of permissions that will<br />

be defined in code.<br />

And defines a label for a set of permissions (both those declared in the<br />

manifest with elements and those declared elsewhere). It affects only how the<br />

permissions are grouped when presented to the user. <strong>The</strong> element does<br />

not specify which permissions belong to the group; it just gives the group a name. A<br />

permission is placed in the group by assigning the group name to the <br />

element's permissionGroup attribute.<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

59


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong> : permission<br />

ACCESS_CHECKIN_PROPERTIES<br />

ACCESS_COARSE_LOCATION<br />

ACCESS_FINE_LOCATION<br />

ACCESS_LOCATION_EXTRA_COMMANDS<br />

ACCESS_MOCK_LOCATION<br />

ACCESS_NETWORK_STATE<br />

ACCESS_SURFACE_FLINGER<br />

ACCESS_WIFI_STATE<br />

ADD_SYSTEM_SERVICE<br />

BATTERY_STATS<br />

BLUETOOTH<br />

BLUETOOTH_ADMIN<br />

BRICK<br />

BROADCAST_PACKAGE_REMOVED<br />

BROADCAST_SMS<br />

BROADCAST_STICKY<br />

BROADCAST_WAP_PUSH<br />

CALL_PHONE<br />

CALL_PRIVILEGED<br />

Allows read/write access to the "properties" table in the checkin database, to change values that<br />

get uploaded.<br />

Allows an application to access coarse (e.g., Cell-ID, WiFi) location<br />

Allows an application to access fine (e.g., GPS) location<br />

Allows an application to access extra location provider commands<br />

Allows an application to create mock location providers for testing<br />

Allows applications to access information about networks<br />

Allows an application to use SurfaceFlinger's low level features<br />

Allows applications to access information about Wi-Fi networks<br />

Allows an application to publish system-level services.<br />

Allows an application to update the collected battery statistics<br />

Allows applications to connect to paired bluetooth devices<br />

Allows applications to discover and pair bluetooth devices<br />

Required to be able to disable the device (very dangerous!).<br />

Allows an application to broadcast a notification that an application package has been removed.<br />

Allows an application to broadcast an SMS receipt notification<br />

Allows an application to broadcast sticky intents.<br />

Allows an application to broadcast a WAP PUSH receipt notification<br />

Allows an application to initiate a phone call without going through the Dialer user interface for<br />

the user to confirm the call being placed.<br />

Allows an application to call any phone number, including emergency numbers, without going<br />

through the Dialer user interface for the user to confirm the call being placed.<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

60


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong> : permission<br />

CAMERA<br />

CHANGE_COMPONENT_ENABLED_STATECOMPONENT ENABLED CHANGE_CONFIGURATION<br />

CHANGE_NETWORK_STATE<br />

CHANGE_WIFI_STATE<br />

CLEAR_APP_CACHE<br />

CLEAR_APP_USER_DATA<br />

CONTROL_LOCATION_UPDATES<br />

DELETE_CACHE_FILES<br />

DELETE_PACKAGES<br />

DEVICE_POWER<br />

DIAGNOSTIC<br />

DISABLE_KEYGUARD<br />

DUMP<br />

EXPAND_STATUS_BAR<br />

FACTORY_TEST<br />

FLASHLIGHT<br />

FORCE_BACK<br />

FOTA_UPDATE<br />

GET_ACCOUNTS<br />

Required to be able to access the camera device.<br />

Allows an application to change whether an application component (other than its own) is<br />

enabled or not.<br />

Allows an application to modify the current configuration, such as locale.<br />

Allows applications to change network connectivity state<br />

Allows applications to change Wi-Fi connectivity state<br />

Allows an application to clear the caches of all installed applications on the device.<br />

Allows an application to clear user data<br />

Allows enabling/disabling location update notifications from the radio.<br />

Allows an application to delete cache files.<br />

Allows an application to delete packages.<br />

Allows low-level access to power management<br />

Allows applications to RW to diagnostic resources.<br />

Allows applications to disable the keyguard<br />

Allows an application to retrieve state dump information from system services.<br />

Allows an application to expand or collapse the status bar.<br />

Run as a manufacturer test application, running as the root user.<br />

Allows access to the flashlight<br />

Allows an application to force a BACK operation on whatever is the top activity.<br />

Allows access to the list of accounts in the Accounts Service<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

61


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong> : permission<br />

GET_PACKAGE_SIZE<br />

GET_TASKSTASKS<br />

HARDWARE_TEST<br />

INJECT_EVENTS<br />

INSTALL_PACKAGES<br />

INTERNAL_SYSTEM_WINDOW<br />

INTERNET<br />

Allows an application to find out the space used by any package.<br />

Allows an application to get information about the currently or recently running tasks: a<br />

thumbnail representation of the tasks, what activities are running in it, etc.<br />

Allows access to hardware peripherals.<br />

Allows an application to inject user events (keys, touch, trackball) into the event stream and<br />

deliver them to ANY window.<br />

Allows an application to install packages.<br />

Allows an application to open windows that are for use by parts of the system user interface.<br />

Allows applications to open network sockets.<br />

MANAGE_APP_TOKENSAPP Allows an application to manage (create, destroy, Z-order) application tokens in the window<br />

manager.<br />

MASTER_CLEAR<br />

MODIFY_AUDIO_SETTINGS<br />

MODIFY_PHONE_STATE<br />

MOUNT_UNMOUNT_FILESYSTEMS<br />

PERSISTENT_ACTIVITY<br />

PROCESS_OUTGOING_CALLS<br />

READ_CALENDAR<br />

READ_CONTACTS<br />

READ_FRAME_BUFFER<br />

READ_INPUT_STATE<br />

READ_LOGS<br />

Allows an application to modify global audio settings<br />

Allows modification of the telephony state - power on, mmi, etc.<br />

Allows mounting and unmounting file systems for removable storage.<br />

Allow an application to make its activities persistent.<br />

Allows an application to monitor, modify, or abort outgoing calls.<br />

Allows an application to read the user's calendar data.<br />

Allows an application to read the user's contacts data.<br />

Allows an application to take screen shots and more generally get access to the frame buffer<br />

data<br />

Allows an application to retrieve the current state of keys and switches.<br />

Allows an application to read the low-level system log files.<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

62


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong> : permission<br />

READ_OWNER_DATA<br />

READ_PHONE_STATE<br />

READ_SMS<br />

READ_SYNC_SETTINGS<br />

READ_SYNC_STATS<br />

REBOOT<br />

RECEIVE_BOOT_COMPLETED<br />

RECEIVE_MMS<br />

RECEIVE_SMS<br />

RECEIVE_WAP_PUSH<br />

RECORD_AUDIO<br />

REORDER_TASKS<br />

RESTART_PACKAGES<br />

SEND_SMS<br />

SET_ACTIVITY_WATCHER<br />

SET_ALWAYS_FINISH<br />

Allows an application to read the owner's data.<br />

Allows read only access to phone state.<br />

Allows an application to read SMS messages.<br />

Allows applications to read the sync settings<br />

Allows applications to read the sync stats<br />

Required to be able to reboot the device.<br />

Allows an application to receive the ACTION_BOOT_COMPLETED that is broadcast after the<br />

system finishes booting.<br />

Allows an application to monitor incoming MMS messages, to record or perform processing on<br />

them.<br />

Allows an application to monitor incoming SMS messages, to record or perform processing on<br />

them.<br />

Allows an application to monitor incoming WAP push messages.<br />

Allows an application to record audio<br />

Allows an application to change the Z-order of tasks<br />

Allows an application to restart other applications.<br />

Allows an application to send SMS messages.<br />

SET_ ANIMATION_ SCALE<br />

Modify the global animation scaling factor.<br />

SET_DEBUG_APP<br />

Allows an application to watch and control how activities are started globally in the system.<br />

Allows an application to control whether activities are immediately finished when put in the<br />

background.<br />

Configure an application for debugging.<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

63


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong> : permission<br />

SET_ORIENTATION<br />

SET_PREFERRED_APPLICATIONS<br />

SET_PROCESS_FOREGROUND<br />

SET_PROCESS_LIMIT<br />

SET_TIME_ZONE<br />

SET_WALLPAPER<br />

Allows low-level access to setting the orientation (actually rotation) of the screen.<br />

Allows an application to modify the list of preferred applications with the<br />

PackageManager.addPackageToPreferred() and<br />

PackageManager.removePackageFromPreferred() methods.<br />

Allows an application to force any currently running process to be in the foreground.<br />

Allows an application to set the maximum number of (not needed) application processes that<br />

can be running.<br />

Allows applications to set the system time zone<br />

Allows applications to set the wallpaper<br />

SET_WALLPAPER_HINTS<br />

_ Allows applications to set the wallpaper p hints<br />

SIGNAL_PERSISTENT_PROCESSES<br />

STATUS_BAR<br />

SUBSCRIBED_FEEDS_READ<br />

SUBSCRIBED_FEEDS_WRITE<br />

SYSTEM_ALERT_WINDOW<br />

VIBRATE<br />

WAKE_LOCK<br />

WRITE_APN_SETTINGS<br />

WRITE_CALENDAR<br />

WRITE_CONTACTS<br />

Allow an application to request that a signal be sent to all persistent processes<br />

Allows an application to open, close, or disable the status bar and its icons.<br />

Allows an application to allow access the subscribed feeds ContentProvider.<br />

Allows an application to open windows using the type TYPE_SYSTEM_ALERT, shown on top<br />

of all other applications.<br />

Allows access to the vibrator<br />

Allows using PowerManager WakeLocks to keep processor from sleeping or screen from<br />

dimming<br />

Allows applications to write the apn settings<br />

Allows an application to write (but not read) the user's calendar data.<br />

Allows an application to write (but not read) the user's contacts data.<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

64


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong> : permission<br />

WRITE_GSERVICES<br />

WRITE_OWNER_DATA<br />

WRITE_SETTINGS<br />

WRITE_SMS<br />

WRITE_SYNC_SETTINGS<br />

Allows an application to modify the Google service map.<br />

Allows an application to write (but not read) the owner's data.<br />

Allows an application to read or write the system settings.<br />

Allows an application to write SMS messages.<br />

Allows applications to write the sync settings<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

65


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong> : permission<br />

# cat /system/etc/permissions.<strong>xml</strong><br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

66


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong> : library<br />

Libraries<br />

Every application is linked against the default Android library, which h includes the basic packages<br />

for building applications (with common classes such as Activity, Service, Intent, View, Button,<br />

Application, ContentProvider, and so on).<br />

However, some packages reside in their own libraries. i If your application uses code from any of<br />

these packages, it must explicitly asked to be linked against them. <strong>The</strong> manifest must contain a<br />

separate element to name each of the libraries. (<strong>The</strong> library name can be found<br />

in the documentation for the package.)<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

67


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong> : library<br />

<br />

8?<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

68


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong> : library<br />

<br />

8?<br />

<br />

<br />

<br />

<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

69


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong> : library<br />

public class NooYawk extends MapActivity {<br />

private MapView map=null;<br />

private MyLocationOverlay me=null;<br />

@Override<br />

public void onCreate(Bundle savedInstanceState) {<br />

super.onCreate(savedInstanceState);<br />

ea e(sa ed s a a e);<br />

setContentView(R.layout.main);<br />

map=(MapView)findViewById(R.id.map);<br />

p ( p);<br />

}<br />

}<br />

map.getController().setCenter(getPoint(40.76793169992044,-73.98180484771729));<br />

map.getController().setZoom(17);<br />

ViewGroup zoom=(ViewGroup)findViewById(R.id.zoom);<br />

( );<br />

zoom.addView(map.getZoomControls());<br />

Drawable marker=getResources().getDrawable(R.drawable.marker);<br />

marker.setBounds(0, 0, marker.getIntrinsicWidth(),<br />

marker.getIntrinsicHeight());<br />

g map.getOverlays().add(new SitesOverlay(marker));<br />

me=new MyLocationOverlay(this, map);<br />

map.getOverlays().add(me);<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

70


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong> : library<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

71


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong> : library (old signing method)<br />

> "c:\Program <strong>File</strong>s\Java\jdk1.6.0_10\bin\keytool.exe"<br />

-genkey -keystore kandroid_keystore –validity 10000 -alias kandroid_key<br />

keystore 암호를 입력하십시오:<br />

새 암호를 다시 입력하십시오:<br />

이름과 성을 입력하십시오.<br />

[Unknown]: Yang JeongSoo<br />

조직 단위 이름을 입력하십시오.<br />

[Unknown]: Kandroid<br />

조직 이름을 입력하십시오.<br />

[Unknown]: Kandroid<br />

구/군/시 이름을 입력하십시오?<br />

[Unknown]: Seoul<br />

시/도 이름을 입력하십시오.<br />

[Unknown]: Seoul<br />

이 조직의 두 자리 국가 코드를 입력하십시오.<br />

[Unknown]: KR<br />

CN=Yang JeongSoo, OU=Kandroid, O=Kandroid, L=Seoul, ST=Seoul, C=KR이(가) 맞습니까?<br />

[아니오]: y<br />

에 대한 키 암호를 입력하십시오.<br />

(keystore 암호와 같은 경우 Enter를 누르십시오):<br />

kandroid_store 파일 생성됨<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

72


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong> : library (old signing method)<br />

D:\android-sdk-windows-1.1_r1\tools>"c:\Program <strong>File</strong>s\Java\jdk1.6.0_10\bin\keytool.exe"<br />

-list -keystore kandroid_keystore<br />

keystore 암호를 입력하십시오:<br />

Keystore 유형: JKS<br />

Keystore 공급자: SUN<br />

Keystore에는 1 항목이 포함되어 있습니다.<br />

kandroid_key, 2009. 3. 16, PrivateKeyEntry,<br />

인증서 지문(MD5): 63:33:67:6F:85:XXXXXXXXXXXXX:14:4F:66:6E<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

73


http://code.google.com/android/maps-api-signup.html<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

74


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong> : library (old signing method)<br />

D:\android-sdk-windows-1.1_r1\tools>"c:\Program <strong>File</strong>s\Java\jdk1.6.0_10\bin\jarsigner.exe"<br />

-verbose -keystore kandroid_keystorekeystore NooYawk.apk apk kandroid_keykey<br />

Enter Passphrase for keystore:<br />

adding: META-INF/KANDROID.SF<br />

adding: META-INF/KANDROID.DSA<br />

DSA<br />

signing: res/drawable/icon.png<br />

signing: res/drawable/marker.png<br />

signing: res/layout/main.<strong>xml</strong><br />

signing: <strong>AndroidManifest</strong>.<strong>xml</strong><br />

signing: resources.arsc<br />

signing: classes.dex<br />

D:\android-sdk-windows-1.1_r1\tools>adb.exe install NooYawk.apk<br />

496 KB/s (0 bytes in 15873.000s)<br />

pkg: /data/local/tmp/NooYawk.apk<br />

Success<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

75


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong> : library<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

76


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong><br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

Structure of the Manifest <strong>File</strong><br />

API Level 3<br />

API Level 4<br />

<br />

<br />

<br />

<br />

<br />

t .. t <br />

<br />

<br />

.. <br />

<br />

<br />

.. <br />

<br />

<br />

API Level 4<br />

<br />

permission><br />

<br />

<br />

<br />

<br />

<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

77


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong> manifest<br />


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong> manifest<br />

android:sharedUserId<br />

<strong>The</strong> name of a Linux user ID that will be shared with other applications. By default, Android<br />

assigns each application its own unique user ID. However, if this attribute is set to the same value<br />

for two or more applications, they will all share the same ID - provided that they are also signed<br />

by the same certificate. t Application with the same user ID can access each other's data and, if<br />

desired, run in the same process.<br />

android:versionCode<br />

An internal version number. This number is used only to determine whether one version is more<br />

recent than another, with higher numbers indicating more recent versions. This is not the version<br />

number shown to users; that number is set by the versionName attribute.<br />

<strong>The</strong> value must be set as an integer, such as "100". You can define it however you want, as long<br />

as each successive version has a higher number. For example, it could be a build number. Or you<br />

could translate a version number in "x.y" format to an integer by encoding the "x" and "y"<br />

separately in the lower and upper 16 bits. Or you could simply increase the number by one each<br />

time a new version is released.<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

79


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong> manifest<br />

<strong>AndroidManifest</strong>.<strong>xml</strong><br />

android:sharedUserId<br />

android:process<br />

Singing by same key<br />

=<br />

<strong>AndroidManifest</strong>.<strong>xml</strong><br />

android:sharedUserId<br />

android:process<br />

Activity<br />

Activity<br />

Task<br />

Activity<br />

Activity<br />

ContentProvider<br />

ContentProvider<br />

Service<br />

Service<br />

APK Package<br />

Process<br />

APK Package<br />

Include<br />

Dalvik VM<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

80


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong><br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

Structure of the Manifest <strong>File</strong><br />

API Level 3<br />

API Level 4<br />

<br />

<br />

<br />

<br />

<br />

t .. t <br />

<br />

<br />

.. <br />

<br />

<br />

.. <br />

<br />

<br />

API Level 4<br />

<br />

permission><br />

<br />

<br />

<br />

<br />

<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

81


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong> manifest/instrumentation<br />

<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

82


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong> manifest/instrumentation<br />

android:functionalTest<br />

Whether or not the Instrumentation class should run as a functional test ? "true" if it should,<br />

and "false" if not. <strong>The</strong> default value is "false".<br />

android:handleProfiling<br />

Whether or not the Instrumentation object will turn profiling on and off ? "true" if it<br />

determines when profiling starts and stops, and "false" if profiling continues the entire time it<br />

is running. A value of "true" enables the object to target profiling at a specific set of<br />

operations. <strong>The</strong> default value is "false".<br />

android:targetPackage<br />

<strong>The</strong> application that the Instrumentation object will run against. An application is identified<br />

by the package name assigned in its manifest file by the element.<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

83


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong> manifest/instrumentation<br />

./apps/Music/tests/<strong>AndroidManifest</strong>.<strong>xml</strong><br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

84


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong> manifest/permission<br />

<br />

./apps/IM/<strong>AndroidManifest</strong>.<strong>xml</strong><br />

<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

85


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong> manifest/permission<br />

Constant V Description<br />

normal 0 A lower-risk permission that gives an application access to isolated application-level<br />

features, with minimal i risk to other applications, the system, or the user. <strong>The</strong> system<br />

automatically grants this type of permission to a requesting application at installation, with<br />

out asking for the user's explicit approval (though the user always has the option to review<br />

these permissions before installing).<br />

dangerous 1 A higher-risk permission that would give a requesting application access to private user<br />

data or control over the device that can negatively impact the user. Because this type of<br />

permission introduces potential risk, the system may not automatically grant it to the<br />

requesting application. For example, any dangerous permissions requested by an<br />

application may be displayed to the user and require confirmation before proceeding, or<br />

some other approach may be taken to avoid the user automatically allowing the use of<br />

such facilities.<br />

signature 2 A permission that the system is to grant only if the requesting application is signed with<br />

the same certificate as the application that declared the permission. If the certificates<br />

match, the system automatically grants the permission without notifying the user or<br />

asking for the user's explicit approval.<br />

Signature 3 A permission that the system is to grant only to packages in the Android system image or<br />

OrSystem<br />

that t are signed with the same certificates. t Please avoid using this option, as the signature<br />

protection level should be sufficient for most needs and works regardless of exactly where<br />

applications are installed. This permission is used for certain special situations where<br />

multiple vendors have applications built in to a system image which need to share specific<br />

features explicitly because they are being built together.<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

86


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong> manifest/permission-group<br />

<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

87


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong> manifest/permission-tree<br />

<br />

Declares the base name for a tree of permissions. <strong>The</strong> application takes ownership of all<br />

names within the tree. It can dynamically add new permissions to the tree by calling<br />

PackageManager.addPermission(). Names within the tree are separated by periods ('.'). For<br />

example, if the base name is com.example.project.taxes, permissions like the following might<br />

be added:<br />

com.example.project.taxes.CALCULATE<br />

com.example.project.taxes.deductions.MAKE_SOME_UP<br />

com.example.project.taxes.deductions.EXAGGERATE<br />

p Note that this element does not declare a permission itself, only a namespace in which further<br />

permissions can be placed. See the element for information on declaring<br />

permissions.<br />

android:name<br />

<strong>The</strong> name that's at the base of the permission tree. It serves as a prefix to all permission<br />

names in the tree. Java-style scoping should be used to ensure that the name is unique. <strong>The</strong><br />

name must have more than two period-separated p seqments in its path - for example,<br />

com.example.base is OK, but com.example is not.<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

88


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong> : menifest/uses-permission<br />

<br />

description:<br />

Requests a permission that the application must be granted in order for it to operate correctly.<br />

Permissions i are granted when the application is installed, not while it's running.<br />

For more information on permissions, see the Permissions section in the introduction and the<br />

separate Security and Permissions document. A list of permissions defined by the base platform<br />

can be found at android.Manifest.permission.<br />

attributes:<br />

android:name<br />

<strong>The</strong> name of the permission. It can be a permission defined by the application with the<br />

element, a permission defined by another application, or one of the standard<br />

system permissions, such as "android.permission.CAMERA" or<br />

"android.permission.READ_CONTACTS". As these examples show, a permission name typically<br />

includes the package name as a prefix.<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

89


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong> : menifest/uses-sdk (old)<br />

<br />

description:<br />

Declares which levels of the Android API the application can run against. <strong>The</strong> level is incremented<br />

when there are additions to the API and resource tree, so an application developed using level 3 of<br />

the API may not run against level 1 or 2, but should run against level 3, 4, 5, and above.<br />

<strong>The</strong> default level is 1.<br />

For more information on the API level, see the Specifying Minimum System API Version section of<br />

Versioning Your Applications.<br />

attributes:<br />

android:minSdkVersion<br />

An integer designating the minimum level of the Android API that's required for the application to run.<br />

Despite its name, this attribute is set to the API level, not to the version number of the SDK (software<br />

development kit). <strong>The</strong> API level is always a single integer; the SDK version may be split into major<br />

and minor components (such as 1.2). You cannot derive the API level from the SDK version number<br />

(for example, it is not the same as the major version or the sum of the major and minor versions). To<br />

learn what the API level is, check the notes that came with the SDK you're using.<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

90


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong> : menifest/uses-sdk (old)<br />

Android 1.1 Version Notes<br />

Date: February 2009<br />

API Level: 2<br />

<br />

...<br />

<br />

...<br />

<br />

• External Libraries : com.google.android.maps<br />

• Device Compatibility : T-Mobile G1<br />

• Built-in Applications<br />

•Alarm Clock / API Demos / Browser / Calculator / Camera / Contacts / Dev Tools<br />

•Dialer / Email / Maps (and StreetView) / Messaging / Music / Pictures / Settings<br />

• UI Localizations<br />

•English, US (en_US) / German (de)<br />

• Resolved Issues<br />

• New Features<br />

• API Changes<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

91


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong> : menifest/uses-sdk (new)<br />

<br />

description:<br />

Lets you express an application's compatibility with one or more versions of the Android platform, by<br />

means of an API Level integer. <strong>The</strong> API Level expressed by an application will be compared to the<br />

API Level of a given Android system, which may vary among different Android devices.<br />

Despite its name, this element is used to specify the API Level, not the version number of the SDK<br />

(software development kit). <strong>The</strong> API Level is always a single integer; the SDK version may be split<br />

into major and minor components (such as 1.5).<br />

You cannot derive the API Level from the SDK version Platform Version API Level<br />

number (for example, it is not the same as the major<br />

Android 2.1 7<br />

version or the sum of the major and minor versions).<br />

Android 2.0.1 6<br />

For more information, read about Android API Levels<br />

Android 2.0 5<br />

and Versioning Your Applications. Android 1.6 4<br />

Android 1.5 3<br />

Android 1.1 2<br />

Android 1.0 1<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

92


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong> : menifest/uses-sdk (new)<br />

android:maxSdkVersion<br />

An integer designating the maximum API Level on which the application is designed to run. <strong>The</strong><br />

Android system will prevent the user from installing the application if the system's API Level is higher<br />

than the value specified in this attribute.<br />

Introduced in: API Level 4<br />

android:targetSdkVersion<br />

An integer designating the API Level that the application is targetting.<br />

With this attribute set, the application says that it is able to run on older versions (down to<br />

minSdkVersion), but was explicitly tested to work with the version specified here. Specifying this<br />

target version allows the platform to disable compatibility settings that are not required for the target<br />

version (which may otherwise be turned on in order to maintain forward-compatibility) or enable<br />

newer features that are not available to older applications. This does not mean that you can program<br />

different features for different versions of the platform?it simply informs the platform that you have<br />

tested against the target version and the platform should not perform any extra work to maintain<br />

forward-compatibility with the target version.<br />

Introduced in: API Level 4<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

93


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong> : menifest/uses-configuration<br />

<br />

description:<br />

Indicates what hardware and software features the application requires. For example, an application<br />

might specify that it requires a physical keyboard or a particular navigation device, like a trackball.<br />

<strong>The</strong> specification is used to avoid installing the application on devices where it will not work.<br />

If an application can work with different device configurations, it should include separate <br />

declarations for each one. Each declaration must be complete. For example, if an<br />

application requires a five-way navigation control, a touch screen that can be operated with a finger,<br />

and either a standard QWERTY keyboard or a numeric 12-key keypad like those found on most<br />

phones, it would specify these requirements with two elements as follows:<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

94


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong> : menifest/uses-configuration<br />

android:reqFiveWayNav<br />

Whether or not the application requires a five-way navigation control<br />

-"true" if it does, and "false" if<br />

not. A five-way control is one that can move the selection up, down, right, or left, and also provides a<br />

way of invoking the current selection. It could be a D-pad (directional pad), trackball, or other device.<br />

If an application requires a directional control, but not a control of a particular type, it can set this<br />

attribute to "true" and ignore the reqNavigation attribute. However, if it requires a particular type of<br />

directional control, it can ignore this attribute and set reqNavigation instead.<br />

android:reqFiveWayNav<br />

Whether or not the application requires a hardware keyboard - "true" if it does, and "false" if not.<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

95


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong> : menifest/uses-configuration<br />

android:reqKeyboardType<br />

<strong>The</strong> type of keyboard the application requires, if any at all. This attribute does not distinguish bet<br />

ween hardware and software keyboards. If a hardware keyboard of a certain type is required, spec<br />

ify the type here and also set the reqHardKeyboard attribute to "true".<br />

<strong>The</strong> value must be one of the following strings:<br />

Value<br />

"undefined"<br />

"nokeys"<br />

"qwerty"<br />

"twelvekey"<br />

Description<br />

<strong>The</strong> application does not require a keyboard. (A keyboard requirement is not defined.)<br />

This is the default value.<br />

<strong>The</strong> application does not require a keyboard.<br />

<strong>The</strong> application requires a standard QWERTY keyboard.<br />

<strong>The</strong> application requires a twelve-key keypad, like those on most phones<br />

- with keys for the digits from 0 through 9 plus star (*) and pound (#) keys.<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

96


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong> : menifest/uses-configuration<br />

android:reqNavigation<br />

<strong>The</strong> navigation device required by the application, if any. <strong>The</strong> value must be one of the following<br />

strings:<br />

Value<br />

"undefined"<br />

"nonav"<br />

"dpad"<br />

"trackball"<br />

"wheel"<br />

Description<br />

<strong>The</strong> application does not require any type of navigation control.<br />

(<strong>The</strong> navigation requirement is not defined.) This is the default value.<br />

<strong>The</strong> application does not require a navigation control.<br />

<strong>The</strong> application requires a D-pad (directional pad) for navigation.<br />

<strong>The</strong> application requires a trackball for navigation.<br />

<strong>The</strong> application requires a navigation wheel.<br />

If an application requires a navigational control, but the exact type of control doesn't matter, it ca<br />

n set the reqFiveWayNav attribute to "true" rather than set this one.<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

97


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong> : menifest/uses-configuration<br />

android:reqTouchScreen<br />

<strong>The</strong> type of touch screen the application requires, if any at all. <strong>The</strong> value must be one of the follo<br />

wing strings:<br />

Value<br />

"undefined"<br />

"notouch"<br />

"stylus"<br />

"finger"<br />

Description<br />

<strong>The</strong> application doesn't require a touch screen.<br />

(<strong>The</strong> touch screen requirement is undefined.) This is the default value.<br />

<strong>The</strong> application doesn't require a touch screen.<br />

<strong>The</strong> application requires a touch screen that's operated with a stylus.<br />

<strong>The</strong> application requires a touch screen that can be operated with a finger.<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

98


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong> : menifest/uses-feature<br />

<br />

description:<br />

This element declares a specific feature used by the application. Android provides some features that<br />

may not be equally supported by all Android devices. In a manner similar to the element,<br />

this element allows an application to specify which device-variable variable features it uses. In this way, the<br />

application will not be installed on devices that do not offer the feature.<br />

For example, an application might specify that it requires a camera with auto-focus capabilities. If a<br />

device does not provide a camera with auto-focus, then it will not allow installation of the application.<br />

In order to maintain strict device compatibility, it's very important that you use this element to declare<br />

all features that your application uses. Failure to declare a feature may result your application being<br />

installed on a device that does not support the feature and your application failing.<br />

For some features, there may exist a specfic attribute that allows you to define a version of the<br />

feature, such as the version of Open GL used (declared with glEsVersion). Other features that either<br />

do or do not exist for a device, such as camera auto-focus, are declared using the name attribute.<br />

Any software or hardware features that may vary among Android-powered devices will be listed on<br />

this page among the attributes below. If you see any features here that you use in your application,<br />

you should include a element for each one. For example, if your application uses the<br />

device camera, then you should include the following in your <strong>AndroidManifest</strong>.<strong>xml</strong>:<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

99


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong> : menifest/uses-feature<br />

<br />

description:<br />

<br />

If you declare "android.hardware.camera", then your application is considered compatible with all<br />

devices that include a camera, regardless of whether auto-focus is available or not. If you also use<br />

the auto-focus features (available through the Camera API), then you need to include an additional<br />

element that declares the "android.hardware.camera.autofocus autofocus" feature. Also note<br />

that you must still request the CAMERA permission. Requesting permission grants your application<br />

access to the appropriate hardware and software, while declaring the features used by your<br />

application ensures proper device compatibility.<br />

Although the element is only activated for devices running API Level 4 or higher, it is<br />

safe to include this for applications that declare a minSdkVersion of "3" or lower. Devices running<br />

older versions of the platform will simply ignore this element, but newer devices will recognize it and<br />

enforce installation restrictions based on whether the device supports the feature.<br />

Note: For each feature required by your application, you must include a new element.<br />

Multiple features cannot be declared in one instance of this element.<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

100


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong> : menifest/uses-feature<br />

android:glEsVersion<br />

<strong>The</strong> GLES version needed by the application. <strong>The</strong> higher 16 bits represent the major number and the<br />

lower 16 bits represent the minor number. For example, for GL 1.2 referring to 0x00000102, the actual<br />

value should be set as 0x00010002.<br />

android:name<br />

<strong>The</strong> name of a feature required by the application. <strong>The</strong> value must be one of the following accepted<br />

strings:<br />

Feature Value Description<br />

Camera "android.hardware.camera" <strong>The</strong> application requires a camera.<br />

"android.hardware.camera.autofocus"<br />

<strong>The</strong> application requires a camera with auto-focus<br />

capability.<br />

As a prerequisite, "android.hardware.camera" must<br />

also be declared with a separate <br />

element.<br />

Note: Any application that requests the CAMERA permission but does not declare any camera<br />

features with the element will be assumed to use all camera features (such as<br />

auto-focus). Thus, the application will not be compatible with devices that do not support all<br />

features. Please use to declare only the camera features that your application<br />

needs.<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

101


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong> : menifest/supports-screen<br />

<br />

description:<br />

Lets you specify the screen dimensions the application supports. By default a modern application<br />

(using API Level 4 or higher) supports all screen sizes and must explicitly disable certain screen sizes<br />

here; older applications are assumed to support only the "normal" screen size. Note that screen size<br />

is a separate axis from density. Screen size is determined as the available pixels to an application<br />

after density scaling has been applied.<br />

Based on the target device screen density, the Android framework will scale down assets by a factor<br />

of 0.75 (low dpi screens) or scale them up by a factor of 1.5 (high dpi screens). <strong>The</strong> screen density is<br />

expressed as dots-per-inch (dpi).<br />

Currently supported densities:<br />

• Low density: 120 dpi<br />

• Medium density: 160 dpi<br />

• High density: 240 dpi<br />

Table of display types:<br />

Low Density Medium Density High Density<br />

Small Screen QVGA n/a VGA<br />

Normal Screen WQVGA HVGA WVGA, FWVGA<br />

Large Screen n/a VGA, WVGA, FWVGA n/a<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

102


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong> : menifest/supports-screen<br />

android:smallScreens<br />

Indicates whether the application supports smaller screen form-factors. A small screen is defined as<br />

one with a smaller aspect ratio than the "normal" (traditional HVGA) screen. An application that does<br />

not support small screens will not be available for small screen devices, because there is little the<br />

platform can do to make such an application work on a smaller screen. Applications using API Level 4<br />

or higher default this to "true", others are "false".<br />

android:normalScreens<br />

Indicates whether an application supports the "normal" screen form-factors. Traditionally this is an<br />

HVGA medium density screen, but WQVGA low density and WVGA high density are also considered to<br />

be normal. This attribute is "true" by default, and applications currently should leave it that way.<br />

android:largeScreens<br />

Indicates whether the application supports larger screen form-factors. A large screen is defined as a<br />

screen that is significantly larger than a "normal" phone screen, and thus may require some special<br />

care on the application's part to make good use of it. An application that does not support large screens<br />

will be placed as a "postage stamp" on such a screen, so that it retains the dimensions it was originally<br />

designed for. Applications using API Level 4 or higher default to "true", others are "false".<br />

android:anyDensity<br />

Indicates whether the application can accommodate any screen density. Older applications (pre API<br />

Level 4) are assumed unable to accomodate all densities and this is "false" by default. Applications<br />

using API Level 4 or higher are assumed able to and this is "true" by default. You can explicitly supply<br />

your abilities i<br />

here.<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

103


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong><br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

Structure of the Manifest <strong>File</strong><br />

API Level 3<br />

API Level 4<br />

<br />

<br />

<br />

<br />

<br />

t .. t <br />

<br />

<br />

.. <br />

<br />

<br />

.. <br />

<br />

<br />

API Level 4<br />

<br />

permission><br />

<br />

<br />

<br />

<br />

<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

104


애플리케이션 개요 : Activities, Tasks, and Processes (1강.review)<br />

An Activity is a “molecule”: a discrete chunk of functionality<br />

A Task is a collection of Activities<br />

A “processes” is a standard Linux process<br />

Activity Activity Activity Activity<br />

Task<br />

ContentProvider<br />

Service<br />

Process<br />

APK Package<br />

ContentProvider<br />

Process<br />

Service<br />

Process<br />

APK Package<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

105


애플리케이션 개요 : Activities and Tasks (1강.review)<br />

Task Info : PackageManager<br />

Task<br />

Root Activity<br />

Activity(Count)<br />

Top Activity<br />

Task<br />

Root Activity<br />

Activity(Count)<br />

Top Activity<br />

Task<br />

Root Activity<br />

Activity(Count)<br />

Top Activity<br />

← Long Click<br />

Task<br />

Root Activity<br />

Activity(Count)<br />

Top Activity<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

106


애플리케이션 개요 : Activities & Tasks (1강.review)<br />

Affinities and new tasks<br />

<strong>The</strong> FLAG_ACTIVITY_NEW_TASK flag<br />

As described earlier, a new activity is, by default, launched into the task of the activity<br />

that called startActivity(). It's pushed onto the same stack as the caller. However, if the<br />

Intent object passed to startActivity() contains the FLAG_ACTIVITY_NEW_TASK flag,<br />

the system looks for a different task to house the new activity. Often, as the name of<br />

the flag implies, it's a new task. However, it doesn't have to be. If there's already an<br />

existing task with the same affinity as the new activity, the activity is launched into that<br />

task. If not, it begins a new task.<br />

<strong>The</strong> allowTaskReparenting attribute<br />

If an activity has its allowTaskReparenting attribute set to "true", it can move from the<br />

task it starts in to the task it has an affinity for when that task comes to the fore. For<br />

example, suppose that an activity that reports weather conditions in selected cities is<br />

defined as part of a travel application. It has the same affinity as other activities in the<br />

same application (the default affinity) and it allows reparenting. One of your activities<br />

starts the weather reporter, so it initially belongs to the same task as your activity.<br />

However, when the travel application next comes forward, the weather reporter will be<br />

reassigned to and displayed with that task.<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

107


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong> manifest/application<br />


Affinities and TaskReparenting<br />

If activity B has its allowTaskReparenting attribute set to "true“,<br />

Activity B can move from the task(Task #1) it starts in to the task(Task #2) it has an affinity<br />

for when that task comes to the foreground<br />

Task #2 Task #2<br />

C<br />

(affinity-Y)<br />

C<br />

(affinity-Y)<br />

B<br />

(affinity-Y)<br />

Task #1<br />

same affinity<br />

Task #1<br />

move<br />

A<br />

(affinity-X)<br />

B<br />

(affinity-Y)<br />

A<br />

(affinity-X)<br />

B<br />

(affinity-Y)<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

109


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong> manifest/application<br />

android:allowClearUserData<br />

Whether or not users are given the option to remove user data - "true" if they are, and "false" if not. If<br />

the value is "true", as it is by default, the application manager includes an option that allows users to<br />

clear the data.<br />

Settings > Applications > Manage Applications > Browser > Clear Data<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

110


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong> manifest/application<br />

android:allowTaskReparenting<br />

Whether or not activities that the application defines can move from the task that started them to the<br />

task they have an affinity for when that task is next brought to the front - "true" if they can move, and<br />

"false" if they must remain with the task where they started. <strong>The</strong> default value is "false".<br />

<strong>The</strong> element has its own allowTaskReparenting attribute that can override the value set here.<br />

See that attribute for more information.<br />

android:debuggable<br />

Whether or not the application can be debugged, even when running on a device in user mode - "true"<br />

if it can be, and "false" if not. <strong>The</strong> default value is "false".<br />

android:description<br />

User-readable text about the application, longer and more descriptive than the application label. <strong>The</strong><br />

value must be set as a reference to a string resource. Unlike the label, it cannot be a raw string. <strong>The</strong>re<br />

is no default value.<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

111


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong> manifest/application<br />

android:enabled<br />

Whether or not the Android system can instantiate components of the application - "true" if it can, and<br />

"false" if not. If the value is "true", each component's enabled attribute determines whether that<br />

component is enabled or not. If the value is "false", it overrides the component-specific values; all<br />

components are disabled.<br />

<strong>The</strong> default value is "true".<br />

android:hasCode<br />

Whether or not the application contains any code - "true" if it does, and "false" if not. When the value is<br />

"false", the system does not try to load any application code when launching components. <strong>The</strong> default<br />

value is "true".<br />

An application would not have any code of its own only if it's using nothing but built-in component<br />

classes, such as an activity that uses the AliasActivity class, a rare occurrence.<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

112


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong> manifest/application<br />

android:manageSpaceActivity<br />

<strong>The</strong> fully qualified name of an Activity subclass that the system can launch to let users manage the<br />

memory occupied by the application on the device. <strong>The</strong> activity should also be declared with an<br />

element.<br />

Settings > Applications > Manage Applications ><br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

113


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong> manifest/application<br />

android:persistent<br />

Whether or not the application should remain running at all times - "true" if it should, and "false" if not.<br />

<strong>The</strong> default value is "false". Applications should not normally set this flag; persistence mode is intended<br />

only for certain system applications.<br />

android:taskAffinity<br />

An affinity name that applies to all activities within the application, except for those that set a different<br />

affinity with their own taskAffinity attributes. See that attribute for more information.<br />

By default, all activities within an application share the same affinity. <strong>The</strong> name of that affinity is<br />

the same as the package name set by the element.<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

114


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong> manifest/application<br />

./apps/Music/<strong>AndroidManifest</strong>.<strong>xml</strong>: android:allowTaskReparenting="true"<br />

./apps/Mms/<strong>AndroidManifest</strong>.<strong>xml</strong>: android:allowTaskReparenting="true“<br />

./apps/IM/samples/PluginDemo/<strong>AndroidManifest</strong>.<strong>xml</strong>: android:taskAffinity="android.task.im"><br />

./apps/IM/<strong>AndroidManifest</strong>.<strong>xml</strong>: android:taskAffinity="android.task.im"<br />

./apps/Music/<strong>AndroidManifest</strong>.<strong>xml</strong>: android:taskAffinity="android.task.music"<br />

./apps/Music/<strong>AndroidManifest</strong>.<strong>xml</strong>: android:taskAffinity=""<br />

./apps/Music/<strong>AndroidManifest</strong>.<strong>xml</strong>: android:taskAffinity="android.task.video"<br />

./apps/Camera/<strong>AndroidManifest</strong>.<strong>xml</strong>: android:taskAffinity=""<br />

./apps/Camera/<strong>AndroidManifest</strong>.<strong>xml</strong>: android:taskAffinity="android.task.camera"<br />

./apps/Camera/<strong>AndroidManifest</strong>.<strong>xml</strong>: android:taskAffinity="android.task.camera"<br />

./apps/Camera/<strong>AndroidManifest</strong>.<strong>xml</strong>: android:taskAffinity="android.task.pictures"<br />

./apps/AlarmClock/<strong>AndroidManifest</strong>.<strong>xml</strong>: android:taskAffinity=":AlarmAlert"<br />

./apps/Calendar/<strong>AndroidManifest</strong>.<strong>xml</strong>: android:taskAffinity="android.task.calendar"<br />

./apps/Contacts/<strong>AndroidManifest</strong>.<strong>xml</strong>: android:taskAffinity="android.task.contacts"<br />

./apps/Contacts/<strong>AndroidManifest</strong>.<strong>xml</strong>: android:taskAffinity=""<br />

./apps/Mms/<strong>AndroidManifest</strong>.<strong>xml</strong>: android:taskAffinity="android.task.mms"<br />

./apps/Mms/<strong>AndroidManifest</strong>.<strong>xml</strong>: android:taskAffinity=""<br />

./apps/Browser/<strong>AndroidManifest</strong>.<strong>xml</strong>: android:taskAffinity="android.task.browser"<br />

./providers/ImProvider/<strong>AndroidManifest</strong>.<strong>xml</strong>: android:taskAffinity="android.task.im"<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

115


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong> : application/uses-library<br />

<br />

description:<br />

Specifies a shared library that the application must be linked against. This element tells the<br />

system to include the library's code in the class loader for the package.<br />

All of the android packages (such as android.app, android.content, android.view, and<br />

android.widget) are in the default library that all applications are automatically linked against.<br />

However, some packages (such as maps and awt are in separate libraries that are not<br />

automatically linked. Consult the documentation for the packages you're using to determine<br />

which library contains the package code.<br />

attributes:<br />

android:name<br />

<strong>The</strong> name of the library.<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

116


애플리케이션 개요 : Activities, Tasks, and Processes (1강.review)<br />

An Activity is a “molecule”: a discrete chunk of functionality<br />

A Task is a collection of Activities<br />

A “processes” is a standard Linux process<br />

Activity Activity Activity Activity<br />

Task<br />

ContentProvider<br />

Service<br />

Process<br />

APK Package<br />

ContentProvider<br />

Process<br />

Service<br />

Process<br />

APK Package<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

117


애플리케이션 개요 : Activities and Tasks (1강.review)<br />

Task Info : PackageManager<br />

Task<br />

Root Activity<br />

Activity(Count)<br />

Top Activity<br />

Task<br />

Root Activity<br />

Activity(Count)<br />

Top Activity<br />

Task<br />

Root Activity<br />

Activity(Count)<br />

Top Activity<br />

← Long Click<br />

Task<br />

Root Activity<br />

Activity(Count)<br />

Top Activity<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

118


애플리케이션 개요 : Activities & Tasks (1강.review)<br />

Affinities and new tasks<br />

<strong>The</strong> FLAG_ACTIVITY_NEW_TASK flag<br />

As described earlier, a new activity is, by default, launched into the task of the activity<br />

that called startActivity(). It's pushed onto the same stack as the caller. However, if the<br />

Intent object passed to startActivity() contains the FLAG_ACTIVITY_NEW_TASK flag,<br />

the system looks for a different task to house the new activity. Often, as the name of<br />

the flag implies, it's a new task. However, it doesn't have to be. If there's already an<br />

existing task with the same affinity as the new activity, the activity is launched into that<br />

task. If not, it begins a new task.<br />

<strong>The</strong> allowTaskReparenting attribute<br />

If an activity has its allowTaskReparenting attribute set to "true", it can move from the<br />

task it starts in to the task it has an affinity for when that task comes to the fore. For<br />

example, suppose that an activity that reports weather conditions in selected cities is<br />

defined as part of a travel application. It has the same affinity as other activities in the<br />

same application (the default affinity) and it allows reparenting. One of your activities<br />

starts the weather reporter, so it initially belongs to the same task as your activity.<br />

However, when the travel application next comes forward, the weather reporter will be<br />

reassigned to and displayed with that task.<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

119


애플리케이션 개요 : Activities & Tasks (1강.review)<br />

Launch modes<br />

Root Activity<br />

Top Activity<br />

Task<br />

standard<br />

A B C C<br />

Task<br />

singleTop<br />

A B C C<br />

If C is singleTop<br />

singleTask<br />

singleInstance<br />

Task<br />

A B C<br />

D<br />

If D is singleTask<br />

or singleInstance<br />

Task<br />

singleTask<br />

D<br />

E<br />

If D is singleTask<br />

Task<br />

If D is singleInstance<br />

singleInstance<br />

E<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

120


애플리케이션 개요 : Activities & Tasks (1강.review)<br />

Launch modes<br />

Which task will hold the activity that responds to the intent. For the "standard" and<br />

"singleTop" modes, it's the task that originated the intent (and called startActivity()) - unless<br />

the Intent object contains the FLAG_ACTIVITY_NEW_TASK flag. In that case, a different task<br />

is chosen as described in the previous section, Affinities and new tasks.<br />

Whether there can be multiple instances of the activity. A "standard" or "singleTop" activity<br />

can be instantiated many times. <strong>The</strong>y can belong to multiple tasks, and a given task can<br />

have multiple instances of the same activity.<br />

Whether the instance can have other activities in its task. A "singleInstance" activity stands<br />

alone as the only activity in its task. If it starts another activity, that activity will be launched<br />

into a different task regardless of its launch mode - as if FLAG_ACTIVITY_NEW_TASK was in<br />

the intent. In all other respects, the "singleInstance" mode is identical to "singleTask".<br />

Whether a new instance of the class will be launched to handle a new intent. For the default<br />

"standard" mode, a new instance is created to respond to every new intent. Each instance<br />

handles just one intent. For the "singleTop" mode, an existing instance of the class is reused<br />

to handle a new intent if it resides at the top of the activity stack of the target task. If it<br />

does not reside at the top, it is not re-used. Instead, a new instance is created for the new<br />

intent and pushed on the stack.<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

121


애플리케이션 개요 : Activities & Tasks (1강.review)<br />

Clearing the stack<br />

<strong>The</strong> alwaysRetainTaskState attribute<br />

If this attribute is set to "true" in the root activity of a task, the default behavior just<br />

described does not happen. <strong>The</strong> task retains all activities in its stack even after a long<br />

period.<br />

<strong>The</strong> clearTaskOnLaunch attribute<br />

If this attribute is set to "true" in the root activity of a task, the stack is cleared down to<br />

the root activity whenever the user leaves the task and returns to it. In other words, it's<br />

the polar opposite of alwaysRetainTaskState. <strong>The</strong> user always returns to the task in its<br />

initial state, even after a momentary absence.<br />

<strong>The</strong> finishOnTaskLaunch attribute<br />

This attribute is like clearTaskOnLaunch, but it operates on a single activity, not an<br />

entire task. And it can cause any activity to go away, including the root activity. When<br />

it's set to "true", the activity remains part of the task only for the current session. If the<br />

user leaves and then returns to the task, it no longer is present.<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

122


애플리케이션 개요 : Activities & Tasks (1강.review)<br />

Clearing the stack<br />

Root Activity<br />

Top Activity<br />

Task<br />

standard<br />

A B C C<br />

Task<br />

alwaysRetainTaskState A B C C<br />

Task<br />

clearTaskOnLaunch A B C C<br />

Task<br />

finishOnTaskLaunch A B C C<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

123


애플리케이션 개요 : Activities & Tasks (1강.review)<br />

Starting tasks<br />

An activity is set up as the entry point for a task by giving it an intent filter with<br />

"android.intent.action.MAIN" as the specified action and<br />

"android.intent.category.LAUNCHER" as the specified category. A filter of this kind causes<br />

an icon and label for the activity to be displayed in the application launcher, giving users a<br />

way both to launch the task and to return to it at any time after it has been launched.<br />

This second ability is important: Users must be able to leave a task and then come back to it<br />

later. For this reason, the two launch modes that mark activities as always initiating a task,<br />

"singleTask" and "singleInstance", should be used only when the activity has a MAIN and<br />

LAUNCHER filter.<br />

A similar difficulty attends the FLAG_ACTIVITY_NEW_TASK flag. If this flag causes an<br />

activity to begin a new task and the user presses the HOME key to leave it, there must be<br />

some way for the user to navigate back to it again. Some entities (such as the notification<br />

manager) always start activities in an external task, never as part of their own, so they<br />

always put FLAG_ACTIVITY_NEW_TASK in the intents they pass to startActivity(). If you<br />

have an activity that can be invoked by an external entity that might use this flag, take care<br />

that the user has a independent way to get back to the task that's started.<br />

For those cases where you don't want the user to be able to return to an activity, set the<br />

element's finishOnTaskLaunch to "true".<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

124


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong> : application/activity (old)<br />

<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

125


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong> : application/activity (new)<br />


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong> : application/activity<br />

android:allowTaskReparenting<br />

Whether or not the activity can move from the task that started it to the task it has an affinity for<br />

when that task is next brought to the front - "true" if it can move, and "false" if it must remain with<br />

the task where it started.<br />

If this attribute is not set, the value set by the corresponding allowTaskReparenting attribute of the<br />

element e e applies to the activity. <strong>The</strong> default value is "false".<br />

Normally when an activity is started, it's associated with the task of the activity that started it and it<br />

stays there for its entire lifetime. You can use this attribute to force it to be re-parented to the task<br />

it has an affinity for when its current task is no longer displayed. Typically, y, it's used to cause the<br />

activities of an application to move to the main task associated with that application.<br />

For example, if an e-mail message contains a link to a web page, clicking the link brings up an<br />

activity that can display the page. That activity is defined by the browser application, but is<br />

launched as part of the e-mail task. If it's reparented to the browser task, it will be shown when<br />

the browser next comes to the front, and will be absent when the e-mail task again comes forward.<br />

<strong>The</strong> affinity of an activity is defined by the taskAffinity attribute. <strong>The</strong> affinity of a task is determined<br />

by reading the affinity of its root activity. <strong>The</strong>refore, by definition, a root activity is always in a task<br />

with the same affinity. Since activities with "singleTask" or "singleInstance" launch modes can only<br />

be at the root of a task, re-parenting is limited to the "standard" and "singleTop" modes. (See also<br />

the launchMode attribute.)<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

127


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong> : application/activity<br />

android:alwaysRetainTaskState<br />

Whether or not the state of the task that the activity is in will always be maintained by the system -<br />

"true" if it will be, and "false" if the system is allowed to reset the task to its initial state in certain<br />

situations. <strong>The</strong> default value is "false". This attribute is meaningful only for the root activity of a<br />

task; it's ignored for all other activities.<br />

Normally, the system clears a task (removes es all activities from the stack above the root activity) in<br />

certain situations when the user re-selects that task from the home screen. Typically, this is done<br />

if the user hasn't visited the task for a certain amount of time, such as 30 minutes.<br />

However, when this attribute is "true", users will always return to the task in its last state,<br />

regardless of how they get there. This is useful, for example, in an application like the web<br />

browser where there is a lot of state (such as multiple open tabs) that users would not like to lose.<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

128


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong> : application/activity<br />

android:clearTaskOnLaunch<br />

Whether or not all activities will be removed from the task, except for the root activity, whenever it<br />

is re-launched from the home screen - "true" if the task is always stripped down to its root activity,<br />

and "false" if not. <strong>The</strong> default value is "false". This attribute is meaningful only for activities that<br />

start a new task (the root activity); it's ignored for all other activities in the task.<br />

When the value is "true", every e time users s start the task again, they are brought to its root activity,<br />

regardless of what they were last doing in the task and regardless of whether they used BACK or<br />

HOME to last leave it. When the value is "false", the task may be cleared of activities in some<br />

situations (see the alwaysRetainTaskState attribute), but not always.<br />

Suppose, for example, that someone launches activity P from the home screen, and from there<br />

goes to activity Q. <strong>The</strong> user next presses HOME, and then returns to activity P. Normally, the user<br />

would see activity Q, since that is what they were last doing in P's task. However, if P set this flag<br />

to "true", all of the activities on top of it (Q in this case) were removed when the user pressed<br />

HOME and the task went to the background. So the user sees only P when returning to the task.<br />

If this attribute and allowTaskReparenting are both "true", any activities that can be re-parented<br />

are moved to the task they share an affinity with; the remaining activities are then dropped, as<br />

described above.<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

129


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong> : application/activity<br />

android:configChanges<br />

Lists configuration changes that the activity will handle itself. When changes that are not listed<br />

occur, the activity is shut down and restarted. When a listed change occurs, the activity remains<br />

running and its onConfigurationChanged() method is called.<br />

Any or all of the following strings can be used to set this attribute. Values are separated by '|‘ - for<br />

example, pe, "locale|navigation|orientation".<br />

a o |o e a o<br />

Value<br />

"mcc"<br />

"mnc"<br />

"locale"<br />

Description<br />

<strong>The</strong> IMSI mobile country code (MCC) has changed - that is, a SIM has been detected and updated the MCC.<br />

<strong>The</strong> IMSI mobile network code (MNC) has changed - that is, a SIM has been detected and updated the MNC.<br />

<strong>The</strong> locale has changed - for example, the user has selected a new language that text should be displayed in.<br />

"touchscreen" <strong>The</strong> touchscreen has changed. (This should never normally happen.)<br />

"keyboard"<br />

<strong>The</strong> keyboard type has changed - for example, the user has plugged in an external keyboard.<br />

"keyboardHidden" <strong>The</strong> keyboard accessibility has changed - for example, the user has slid the keyboard out to expose it.<br />

"navigation"<br />

<strong>The</strong> navigation type has changed. (This should never normally happen.)<br />

"orientation"<br />

<strong>The</strong> screen orientation has changed - that is, the user has rotated the device.<br />

"fontScale"<br />

<strong>The</strong> font scaling factor has changed - that is, the user has selected a new global font size.<br />

All of these configuration changes can impact the resource values seen by the application.<br />

<strong>The</strong>refore, when onConfigurationChanged() is called, it will generally be necessary to again<br />

retrieve all resources (including view layouts, drawables, and so on) to correctly handle the<br />

change.<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

130


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong> : application/activity<br />

android:enabled<br />

Whether or not the activity can be instantiated by the system -"true" if it can be, and "false" if not.<br />

<strong>The</strong> default value is "true".<br />

<strong>The</strong> element has its own enabled attribute that applies to all application<br />

components, including activities. <strong>The</strong> and attributes must both be "true"<br />

(as they both are by default) for the system to be able to instantiate a the activity. If either e is "false",<br />

it cannot be instantiated.<br />

android:excludeFromRecents<br />

Whether or not the activity should be excluded from the list of recently launched activities that can<br />

be displayed to users - "true" if it should be excluded, and "false" if it should be included. <strong>The</strong><br />

default value is "false".<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

131


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong> : application/activity<br />

android:exported<br />

Whether or not the activity can be launched by components of other applications - "true" if it can<br />

be, and "false" if not. If "false", the activity can be launched only by components of the same<br />

application or applications with the same user ID.<br />

<strong>The</strong> default value depends on whether the activity contains intent filters. <strong>The</strong> absence of any<br />

filters means that the activity can be invoked only by specifying its exact class name. This implies<br />

that the activity is intended only for application-internal use (since others would not know the<br />

class name). So in this case, the default value is "false". On the other hand, the presence of at<br />

least one filter implies that the activity is intended for external use, so the default value is "true".<br />

This attribute is not the only way to limit an activity's exposure to other applications. You can also<br />

use a permission to limit the external entities that can invoke the activity (see the permission<br />

attribute).<br />

android:finishOnTaskLaunch<br />

Whether or not an existing instance of the activity should be shut down (finished) whenever the<br />

user again launches its task (chooses the task on the home screen) - "true" if it should be shut<br />

down, and "false" if not. <strong>The</strong> default value is "false".<br />

If this attribute and allowTaskReparenting are both "true", this attribute trumps the other. <strong>The</strong><br />

affinity of the activity is ignored. <strong>The</strong> activity is not re-parented, but destroyed.<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

132


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong> : application/activity<br />

android:launchMode<br />

An instruction on how the activity should be launched. <strong>The</strong>re are four modes that work in<br />

conjunction with activity flags (FLAG_ACTIVITY_* constants) in Intent objects to determine what<br />

should happen when the activity is called upon to handle an intent. <strong>The</strong>y are:<br />

"standard"<br />

"singleTop"<br />

ge "singleTask"<br />

"singleInstance"<br />

<strong>The</strong> default mode is "standard".<br />

<strong>The</strong> modes fall into two main groups, with "standard" and "singleTop" activities on one side, and<br />

"singleTask" and "singleInstance" activities on the other. An activity with the "standard" or<br />

"singleTop" launch mode can be instantiated multiple times. <strong>The</strong> instances can belong to any task<br />

and can be located anywhere in the activity stack. Typically, they're launched into the task that<br />

called startActivity() (unless the Intent object contains a FLAG_ACTIVITY_NEW_TASK instruction,<br />

in which case a different task is chosen ? see the taskAffinity attribute).<br />

In contrast, "singleTask" and "singleInstance" activities can only begin a task. <strong>The</strong>y are always at<br />

the root of the activity stack. Moreover, the device can hold only one instance of the activity at a<br />

time - only one such task.<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

133


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong> : application/activity<br />

<strong>The</strong> "standard" and "singleTop" modes differ from each other in just one respect: Every time<br />

there's new intent for a "standard" activity, a new instance of the class is created to respond to<br />

that intent. Each instance handles a single intent. Similarly, a new instance of a "singleTop"<br />

activity may also be created to handle a new intent. However, if the target task already has an<br />

existing instance of the activity at the top of its stack, that instance will receive the new intent (in<br />

an onNewIntent() e call); a new instance is not created. ed In other circumstances cu ces ? for example, e, if an<br />

existing instance of the "singleTop" activity is in the target task, but not at the top of the stack, or if<br />

it's at the top of a stack, but not in the target task ? a new instance would be created and pushed<br />

on the stack.<br />

<strong>The</strong> "singleTask" and "singleInstance" modes also differ from each other in only one respect: A<br />

"singleTask" activity allows other activities to be part of its task. It's at the root of the activity stack,<br />

but other activities (necessarily "standard" and "singleTop" activities) can be launched into the<br />

same task. A "singleInstance" activity, on the other hand, permits no other activities to be part of<br />

its task. It's the only activity in the task. If it starts another activity, that activity is assigned to a<br />

different task - as if FLAG_ACTIVITY_NEW_TASK was in the intent.<br />

For more information on launch modes and their interaction with Intent flags, see the Activities<br />

and Tasks section of the Application Fundamentals document.<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

134


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong> : application/activity<br />

android:multiprocess<br />

Whether an instance of the activity can be launched into the process of the component that<br />

started it -"true" if it can be, and "false" if not. <strong>The</strong> default value is "false".<br />

Normally, a new instance of an activity is launched into the process of the application that defined<br />

it, so all instances of the activity run in the same process. However, if this flag is set to "true",<br />

instances of the activity can run in multiple processes, allowing the system to create instances<br />

wherever e e they are used (provided permissions s allow it), something that is almost never e necessary<br />

or desirable.<br />

android:name<br />

<strong>The</strong> name of the class that implements the activity, a subclass of Activity. <strong>The</strong> attribute value<br />

should be a fully qualified class name (such as, "com.example.project.ExtracurricularActivity").<br />

However, as a shorthand, if the first character of the name is a period (for example,<br />

".ExtracurricularActivity"), it is appended to the package name specified in the <br />

element.<br />

<strong>The</strong>re is no default. <strong>The</strong> name must be specified.<br />

android:permission<br />

<strong>The</strong> name of a permission that clients must have to launch the activity or otherwise get it to<br />

respond to an intent. If a caller of startActivity() or startActivityForResult() has not been granted<br />

the specified permission, its intent will not be delivered to the activity.<br />

If this attribute is not set, the permission set by the element's permission attribute<br />

applies to the activity. If neither attribute is set, the activity is not protected by a permission.<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

135


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong> : application/activity<br />

android:process<br />

<strong>The</strong> name of the process in which the activity should run. Normally, all components of an<br />

application run in the default process created for the application. It has the same name as the<br />

application package. <strong>The</strong> element's process attribute can set a different default for<br />

all components. But each component can override the default, allowing you to spread your<br />

application across multiple processes.<br />

If the name assigned to this attribute begins with a colon (':'), a new process, private to the<br />

application, is created when it's needed and the activity runs in that process. If the process name<br />

begins with a lowercase character, the activity will run in a global process of that name, provided<br />

that it has permission to do so. This allows components in different applications to share a<br />

process, reducing resource usage.<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

136


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong> : application/activity<br />

android:screenOrientation<br />

<strong>The</strong> orientation of the activity's display on the device. <strong>The</strong> value can be any one of the following<br />

strings:<br />

"unspecified"<br />

"landscape"<br />

"portrait"<br />

"user"<br />

"behind"<br />

"sensor"<br />

"nosensor"<br />

<strong>The</strong> default value. <strong>The</strong> system chooses the orientation. <strong>The</strong> policy it uses, and therefore<br />

the choices made in specific contexts, may differ from device to device.<br />

Landscape orientation (the display is wider than it is tall).<br />

Portrait orientation (the display is taller than it is wide).<br />

<strong>The</strong> user's current preferred orientation.<br />

<strong>The</strong> same orientation as the activity that's immediately beneath it in the activity stack.<br />

<strong>The</strong> orientation determined by a physical orientation sensor. <strong>The</strong> orientation of the display<br />

depends on how the user is holding the device; it changes when the user rotates the<br />

device.<br />

An orientation determined without reference to a physical orientation sensor. <strong>The</strong> sensor<br />

is ignored, so the display will not rotate based on how the user moves the device. Except<br />

for this distinction, the system chooses the orientation using the same policy as for the<br />

"unspecified" setting.<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

137


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong> : application/activity<br />

android:stateNotNeeded<br />

Whether or not the activity can be killed and successfully restarted without having saved its state -<br />

"true" if it can be restarted without reference to its previous state, and "false" if its previous state is<br />

required. <strong>The</strong> default value is "false".<br />

Normally, before an activity is temporarily shut down to save resources, its onSaveInstanceState()<br />

method is called. This method stores the current state of the activity in a Bundle object, which is<br />

then passed to onCreate() when the activity is restarted. If this attribute is set to "true",<br />

onSaveInstanceState() may not be called and onCreate() will be passed null instead of the<br />

Bundle - just as it was when the activity started for the first time.<br />

A "true" setting ensures that the activity can be restarted in the absence of retained state. For<br />

example, the activity that displays the home screen uses this setting to make sure that it does not<br />

get removed if it crashes for some reason.<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

138


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong> : application/activity<br />

android:taskAffinity<br />

<strong>The</strong> task that the activity has an affinity for. Activities with the same affinity conceptually belong to the<br />

same task (to the same "application" from the user's perspective). <strong>The</strong> affinity of a task is determined<br />

by the affinity of its root activity.<br />

<strong>The</strong> affinity determines two things - the task that the activity is re-parented to (see the<br />

allowTaskReparenting attribute) and the task that will house the activity when it is launched with the<br />

FLAG_ACTIVITY_NEW_TASK flag.<br />

By default, all activities in an application have the same affinity. You can set this attribute to group them<br />

differently, and even place activities defined in different applications within the same task. To specify<br />

that the activity does not have an affinity for any task, set it to an empty string.<br />

If this attribute is not set, the activity inherits the affinity set for the application (see the <br />

element's taskAffinity attribute). <strong>The</strong> name of the default affinity for an application is the package name<br />

set by the element.<br />

android:theme<br />

A reference to a style resource defining an overall theme for the activity. This automatically sets the<br />

activity's context to use this theme (see set<strong>The</strong>me(), and may also cause "starting" animations prior to<br />

the activity being launched (to better match what the activity actually looks like).<br />

If this attribute is not set, the activity inherits the theme set for the application as a whole ? see the<br />

i element's theme attribute. If that attribute is also not set, the default system theme is<br />

used.<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

139


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong> : application/activity<br />

android:windowSoftInputMode<br />

How the main window of the activity interacts with the window containing the on-screen soft keyboard.<br />

<strong>The</strong> setting for this attribute affects two things:<br />

• <strong>The</strong> state of the soft keyboard - whether it is hidden or visible - when the activity becomes the focus of<br />

user attention.<br />

• <strong>The</strong> adjustment made to the activity's main window - whether it is resized smaller to make room for<br />

the soft keyboard or whether its contents pan to make the current focus visible when part of the window<br />

is covered by the soft keyboard.<br />

<strong>The</strong> setting must be one of the values listed in the following table, or a combination of one "state..."<br />

value plus one "adjust..." value. Setting multiple values in either group - multiple "state..." values, for<br />

example &mdash has undefined results. Individual values are separated by a vertical bar (|). For<br />

example:<br />

<br />

Values set here (other than "stateUnspecified" and "adjustUnspecified") override values set in the<br />

theme.<br />

중략..<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

140


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong> : application/activity-alias<br />

<br />

android:name="string"<br />

android:permission="string"<br />

android:targetActivity="string" ><br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

141


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong> : application/activity-alias<br />

android:name<br />

A unique name for the alias. <strong>The</strong> name should resemble a fully qualified class name. But, unlike the<br />

name of the target activity, the alias name is arbitrary; it does not refer to an actual class.<br />

android:targetActivity<br />

<strong>The</strong> name of the activity that can be activated through the alias. This name must match the name<br />

attribute of an element that precedes the alias in the manifest.<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

142


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong> : application/receiver<br />


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong> : application/service<br />


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong> : component(a,s,r)/intent-filter<br />

<br />

. . .<br />

<br />

android:priority<br />

d o <strong>The</strong> priority that should be given to the parent component with regard to handling intents of the type<br />

described by the filter. This attribute has meaning for both activities and broadcast receivers:<br />

• It provides information about how able an activity is to respond to an intent that matches the filter,<br />

relative to other activities that could also respond to the intent. When an intent could be handled by<br />

multiple activities with different priorities, Android will consider only those with higher priority values<br />

as potential targets for the intent.<br />

• It controls the order in which broadcast receivers are executed to receive broadcast messages.<br />

Those with higher priority values are called before those with lower values. (<strong>The</strong> order applies only to<br />

synchronous messages; it's ignored for asynchronous messages.)<br />

Use this attribute only if you really need to impose a specific order in which the broadcasts are<br />

received, or want to force Android to prefer one activity over others.<br />

<strong>The</strong> value must be an integer, such as "100". Higher numbers have a higher priority.<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

145


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong> : intent-filter/action<br />

<br />

android:name<br />

<strong>The</strong> name of the action. Some standard actions are defined in the Intent class as ACTION_string<br />

constants. t To assign one of these actions to this attribute, t prepend "android.intent.action." i t ti "to the<br />

string that follows ACTION_. For example, for ACTION_MAIN, use "android.intent.action.MAIN"<br />

and for ACTION_WEB_SEARCH, use "android.intent.action.WEB_SEARCH".<br />

For actions you define, it's best to use the package name as a prefix to ensure uniqueness. For<br />

example, a TRANSMOGRIFY action might be specified as follows:<br />

<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

146


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong> : intent-filter/category<br />

<br />

android:name<br />

<strong>The</strong> name of the category. Standard categories are defined in the Intent class as<br />

CATEGORY_name constants. t <strong>The</strong> name assigned here can be derived d from those constants t by<br />

prefixing "android.intent.category." to the name that follows CATEGORY_.<br />

For example, the string value for CATEGORY_LAUNCHER is<br />

"android.intent.category.LAUNCHER".<br />

i t t Custom categories should use the package name as a prefix, to ensure that they are unique.<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

147


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong> : intent-filter/data<br />

<br />

다음장에서 상세 설명<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

148


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong> : intent-filter/data<br />

android:host<br />

<strong>The</strong> host part of a URI authority. This attribute is meaningless unless a scheme attribute is also<br />

specified for the filter.<br />

android:path<br />

android:pathPrefix<br />

android:pathPattern<br />

<strong>The</strong> path part of a URI. <strong>The</strong> path attribute specifies a complete path that is matched against the<br />

complete path in an Intent object. <strong>The</strong> pathPrefix attribute specifies a partial path that is matched<br />

against only the initial part of the path in the Intent object. <strong>The</strong> pathPattern attribute specifies a<br />

complete path that is matched against the complete path in the Intent object, but it can contain the<br />

following wildcards:<br />

An asterisk ('*') matches a sequence of 0 to many occurrences of the immediately preceding character.<br />

A period followed by an asterisk (".*") matches any sequence of 0 to many characters.<br />

Because '\' is used as an escape character when the string is read from XML (before it is parsed as a<br />

pattern), you will need to double-escape: For example, a literal '*' would be written as "\\*" and a literal<br />

'\' would be written as "\\\\" . This is basically the same as what you would need to write if constructing<br />

the string in Java code.<br />

For more information on these three types of patterns, see the descriptions of PATTERN_LITERAL,<br />

PATTERN_PREFIX, PREFIX and PATTERN_SIMPLE_GLOB in the PatternMatcher class.<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

149


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong> : intent-filter/data<br />

android:mimeType<br />

A MIME media type, such as image/jpeg or audio/mpeg4-generic. generic <strong>The</strong> subtype can be the asterisk<br />

wildcard (*) to indicate that any subtype matches.<br />

<strong>The</strong>se attributes are meaningful only if the scheme and host attributes are also specified for the filter.<br />

android:port<br />

<strong>The</strong> port part of a URI authority. This attribute is meaningful only if the scheme and host attributes are<br />

also specified for the filter.<br />

android:scheme<br />

<strong>The</strong> scheme part of a URI. This is the minimal essential attribute for specifying a URI; at least one<br />

scheme attribute must be set for the filter, or none of the other URI attributes are meaningful.<br />

A scheme is specified without the trailing colon (for example, http, rather than http:).<br />

If the filter has a data type set (the mimeType attribute) but no scheme, the content: and file: schemes<br />

are assumed.<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

150


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong> : application/provider<br />

<br />

. . .<br />

<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

151


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong> : application/provider<br />

android:authorities<br />

A list of one or more URI authorities that identify data under the purview of the content provider.<br />

Multiple authorities are listed by separating their names with a semicolon. To avoid conflicts, authority<br />

names should use a Java-style naming convention (such as com.example.provider.cartoonprovider).<br />

Typically, it's the name of the ContentProvider subclass.<br />

<strong>The</strong>re is no default. At least one authority must be specified.<br />

android:grantUriPermissions<br />

Whether or not those who ordinarily would not have permission to access the content provider's data can be granted<br />

permission i to do so, temporarily overcoming the restriction ti imposed by the readPermission, i writePermission, i i and<br />

permission attributes ? "true" if permission can be granted, and "{@ code false}" if not. If "true", permission can be<br />

granted to any of the content provider's data. If "false", permission can be granted only to the data subsets listed in<br />

subelements, if any. <strong>The</strong> default value is "false".<br />

Granting permission is a way of giving an application component one-time access to data protected by a permission. For<br />

example, when an e-mail message contains an attachment, the mail application may call upon the appropriate viewer to<br />

open it, even though the viewer doesn't have general permission to look at all the content provider's data.<br />

In such cases, permission is granted by FLAG_GRANT_READ_URI_PERMISSION and<br />

FLAG_GRANT_WRITE_URI_PERMISSION GRANT flags in the Intent object that activates the component. For example, the<br />

mail application might put FLAG_GRANT_READ_URI_PERMISSION in the Intent passed to Context.startActivity(). <strong>The</strong><br />

permission is specific to the URI in the Intent.<br />

If you enable this feature, either by setting this attribute to "true" or by defining subelements, you<br />

must call Context.revokeUriPermission() when a covered URI is deleted from the provider.<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

152


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong> : application/provider<br />

android:initOrder<br />

<strong>The</strong> order in which the content provider should be instantiated, relative to other content providers<br />

hosted by the same process. When there are dependencies among content providers, setting this<br />

attribute for each of them ensures that they are created in the order required by those dependencies.<br />

<strong>The</strong> value is a simple integer, with higher numbers being initialized first.<br />

android:readPermission<br />

A permission that clients must have to query the content provider. See also the permission and<br />

writePermission attributes.<br />

android:syncable<br />

Whether or not the data under the content provider's control is to be synchronized with data on a<br />

server ? "true" if it is to be synchronized, and "{@ code false}" if not.<br />

android:writePermission<br />

A permission that clients must have to make changes to the data controlled by the content provider.<br />

See also the permission and readPermission attributes.<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

153


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong> : provider/grant-uri-permisson<br />

<br />

description:<br />

Specifies which data subsets of the parent content provider permission can be granted for. Data<br />

subsets are indicated by the path part of a content: URI. (<strong>The</strong> authority part of the URI identifies<br />

the content provider.) Granting permission is a way of enabling clients of the provider that don't<br />

normally have permission to access its data to overcome that restriction on a one-time basis.<br />

If a content provider's grantUriPermissions attribute is "true", permission can be granted<br />

for any the data under the provider's purview. However, if that attribute is "false",<br />

permission can be granted only to data subsets that are specified by this element. A<br />

provider can contain any number of elements. Each one can specify only<br />

one path (only one of the three possible attributes).<br />

For information on how permission is granted, see the element's<br />

grantUriPermissions attribute.<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

154


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong> : provider/path-permisson<br />


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong> : component/meta-data<br />

<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

156


<strong>The</strong> <strong>AndroidManifest</strong>.<strong>xml</strong> <strong>File</strong> : component(all)/meta-data<br />

android:resource<br />

A reference to a resource. <strong>The</strong> ID of the resource is the value assigned to the item. <strong>The</strong> ID can be<br />

retrieved from the meta-data Bundle by the Bundle.getInt() method.<br />

android:value<br />

<strong>The</strong> value assigned to the item. <strong>The</strong> data types that can be assigned as values and the Bundle<br />

methods that components use to retrieve those values are listed in the following table:<br />

Type<br />

String value, using double backslashes (\\) to escape characters ? such as "\\n" and<br />

"\\uxxxxx" for a Unicode character.<br />

Integer value, such as "100"<br />

Boolean value, either "true" or "false"<br />

Color value, in the form "#rgb", "#argb", "#rrggbb", or "#aarrggbb"<br />

Float value, such as "1.23"<br />

Bundle method<br />

getString()<br />

getInt()<br />

getBoolean()<br />

getString()<br />

getFloat()<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

157


안드로이드 애플리케이션 교육 자료 – 9<br />

Location and Google Map API 실습<br />

www.kandroid.org 운영자 : 양정수 (yangjeongsoo@gmail.com), 닉네임:들풀


Google MapView API Demo Key<br />

http://code.google.com/android/maps-api-signup.html<br />

res/layout/<br />


Google Map API 사용법 (using debug keystore)<br />

1. Import MyMap Project into Eclipse Workplace<br />

2. Check debug keystore<br />

Eclipse > Window > Preferences > Android > Build<br />

ex) Default debug keystore<br />

C:\Documents and Settings\kandroid\.android\debug.keystore<br />

3. Get MD5 FingerPrint<br />

keytool -list -alias androiddebugkey -keystore " C:\Documents and<br />

Settings\kandroid\.android\debug.keystore " -storepass android -keypass android<br />

ex ) MD5지문 - E3:A8:7C:67:A3:E6:A7:39:B5:19:F3:2C:F6:A5:30:D3<br />

4. Get Google Map API Key<br />

http://code.google.com/android/maps-api-signup.html<br />

5. Use Google Map API Key, Build with debug keystore, Install, and Start .apk<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

160


Google Map API 사용법 (using custom keystore)<br />

1. On Eclipse Project, Right-click<br />

2. Create Custom keystore and Build .apk with your custom keystore<br />

Android Tools > Export Signed Application Package > …. ><br />

Result 1 : Your custom keystore location and keystore Info.<br />

Result 2 : Signed apk using custom keystore : c:\MyMap.apk<br />

M 3. Get MD5 FingerPrint from your custom keystore<br />

keytool -list -alias androiddebugkey -keystore "C\D C:\Documents and<br />

Settings\kandroid\.android\debug.keystore " -storepass android -keypass android<br />

ex ) MD5지문 - E3:A8:7C:67:A3:E6:A7:39:B5:19:F3:2C:F6:A5:30:D3<br />

4. Get Google Map API Key<br />

http://code.google.com/android/maps-api-signup.html<br />

5. Use Google Map API Key, Build with custom keystore, Install, and Start .apk<br />

cf : adb.exe uninstall <br />

adb.exe install <br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

161


Location<br />

Overview<br />

<strong>The</strong> Android SDK includes two packages that provide Android's primary support for building<br />

location-based services: android.location and com.google.android.maps. Please read on below<br />

for a brief introduction to each package.<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

162


Location<br />

android.location<br />

This package contains several classes related to location services in the Android platform. Most<br />

importantly, it introduces the LocationManager service, which provides an API to determine location and<br />

bearing if the underlying device (if it supports the service). <strong>The</strong> LocationManager should not be<br />

instantiated ti t directly; rather, a handle to it should be retrieved via<br />

getSystemService(Context.LOCATION_SERVICE).<br />

Once your application has a handle to the LocationManager, your application will be able to do three<br />

things:<br />

• Query for the list of all LocationProviders known to the LocationManager for its last known location.<br />

• Register/unregister for periodic updates of current location from a LocationProvider (specified either by<br />

Criteria or name).<br />

• Register/unregister for a given Intent to be fired if the device comes within a given proximity (specified<br />

by radius in meters) of a given lat/long.<br />

However, during initial development, you may not have access to real data from a real location provider<br />

(Network or GPS). So it may be necessary to spoof some data for your application, with some mock<br />

location data.<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

163


Location<br />

Providing Mock Location Data<br />

When testing your application on the Android emulator, there are a couple different ways to send it some<br />

spoof location data: with the DDMS tool or the "geo" command.<br />

Using DDMS<br />

With the DDMS tool, you can simulate location data a few different ways:<br />

• Manually send individual id longitude/latitude tit d coordinates to the device.<br />

• Use a GPX file describing a route for playback to the device.<br />

• Use a KML file describing individual placemarks for sequenced playback to the device.<br />

For more information on using DDMS to spoof location data, see the Using DDMS guide.<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

164


Location<br />

Providing Mock Location Data<br />

Using the "geo" command<br />

Launch your application in the Android emulator and open a terminal/console in your SDK's /tools<br />

directory. Now you can use:<br />

> telnet localhost 5554<br />

• geo fix to send a fixed geo-location.<br />

This command accepts a longitude and latitude in decimal degrees, and an optional altitude in<br />

meters.<br />

For example:<br />

geo fix -121.45356 46.51119 4392<br />

geo nmea to send an NMEA 0183 sentence.<br />

This command accepts a single NMEA sentence of type '$GPGGA' (fix data) or '$GPRMC' (transit<br />

data).<br />

For example:<br />

geo nmea $GPRMC,081836,A,3751.65,S,14507.36,E,000.0,360.0,130998,011.3,E*62<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

165


Location (1.1 까지만 유효..)<br />

com.google.android.maps<br />

This package introduces a number of classes related to rendering, controlling, and overlaying<br />

customized information on your own Google Mapified Activity. <strong>The</strong> most important of which is the<br />

MapView class, which automagically draws you a basic Google Map when you add a MapView to your<br />

layout. Note that, t if you want to do so, then your Activity it that t handles the MapView must extend<br />

MapActivity.<br />

Also note that you must obtain a MapView API Key from the Google Maps service, before your MapView<br />

can load maps data. For more information, see Obtaining i a MapView API Key.<br />

Once you've created a MapView, you'll probably want to use getController() to retrieve a MapController,<br />

for controlling and animating the map, and ItemizedOverlay to draw Overlays and other information on<br />

the Map.<br />

This is not a standard package in the Android library. In order to use it, you must add the following node<br />

to your Android Manifest file, as a child of the element:<br />

<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

166


Location (1.5 Special Feature)<br />

Google Maps External Library<br />

make it easier for you to add powerful mapping capabilities to your application, Google provides a Maps external library<br />

that includes the com.google.android.maps package. <strong>The</strong> classes of the com.google.android.maps package offer built-in<br />

downloading, rendering, and caching of Maps tiles, as well as a variety of display options and controls.<br />

<strong>The</strong> key class in the Maps package is com.google.android.maps.MapView, g p a subclass of ViewGroup. A MapView displays<br />

a map with data obtained from the Google Maps service. When the MapView has focus, it will capture keypresses and<br />

touch gestures to pan and zoom the map automatically, including handling network requests for additional maps tiles. It<br />

also provides all of the UI elements necessary for users to control the map. Your application can also use MapView class<br />

methods to control the MapView programmatically and draw a number of Overlay types on top of the map.<br />

In general, the MapView class provides a wrapper around the Google Maps API that lets your application manipulate<br />

Google Maps data through class methods, and it lets you work with Maps data as you would other types of Views.<br />

<strong>The</strong> Maps external library is not part of the standard Android library, so it may not be present on some compliant Androidpowered<br />

devices. Similarly, the Maps external library is not included in the standard Android library provided in the SDK.<br />

So that you can develop using the classes of the com.google.android.maps package, the Maps external library is made<br />

available to you as part of the Google APIs add-on for the Android SDK.<br />

To learn more about the Maps external library and how to download and use the Google APIs add-on, visit<br />

http://code.google.com/android/add-ons/google-apis<br />

For your convenience, the Google APIs add-on is also included in the Android SDK.<br />

Note: In order to display Google Maps data in a MapView, you must register with the Google Maps service and obtain a<br />

Maps API Key. For information about how to get a Maps API Key, see Obtaining a Maps API Key.<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

167


안드로이드 개발 프로세스(Android 1.5 이후 Feature 1강. Review)<br />

안드로이드 애플리케이션 빌드 프로세스(1)<br />

Eclipse<br />

(ADT Plug-in)<br />

Java<br />

compiler<br />

dx / aapt<br />

converter<br />

결과물:<br />

Unsigned APK<br />

Java<br />

Dalvik<br />

(classes)<br />

(.dex)<br />

Ref. Libs<br />

Unsigned<br />

Android<br />

Application<br />

(.apk)<br />

∥<br />

Resources<br />

Manifest<br />

XML Res.<br />

Compilation<br />

+<br />

Other Res.<br />

Pre-process<br />

Zip<br />

Compressed<br />

<strong>File</strong><br />

Key<br />

(Debug Key<br />

Custom Key)<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

168


안드로이드 개발 프로세스(Android 1.5 이후 Feature 1강. Review)<br />

안드로이드 애플리케이션 빌드 프로세스(2)<br />

jarsigner<br />

(keytool)<br />

zipalign<br />

adb<br />

install<br />

am<br />

start<br />

결과물:<br />

App. Launch<br />

Android<br />

Application<br />

(.apk)<br />

∥<br />

Zip<br />

Compressed<br />

<strong>File</strong><br />

Key<br />

(Debug Key<br />

Custom Key)<br />

Signed<br />

Android<br />

Application<br />

(.apk)<br />

by<br />

Debug Key<br />

Signed<br />

Android<br />

Application<br />

(.apk)<br />

by<br />

Custom Key<br />

Aligned<br />

Android<br />

Application<br />

(.apk)<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

169


Application Signing : 애플리케이션 빌드,설치,런치 프로세스(1)<br />

1<br />

2<br />

Application Signing based on Debug KeyStore (eclipse/window/preferences/Android/Build/Default debug keystore)<br />

jarsigner.exe -verbose -keystore “debug.keystore" MyMap.apk androiddebugkey<br />

Uninstall & Install Package<br />

D:\android-sdk-windows-1.5_r3\tools>adb.exe uninstall org.kandroid.example.mymap<br />

D:\android-sdk-windows-1.5_r3\tools>adb.exe install MyMap.apk<br />

3<br />

Launch hA Activity<br />

it<br />

1. D:\android-sdk-windows-1.5_r3\tools>adb.exe shell am start -D -n org.kandroid.example.mymap/.MyMap<br />

Starting: Intent { comp={org.kandroid.example.mymap/org.kandroid.example.mymap.MyMap} }<br />

2. am start –n org.kandroid.example.mymap/.MyMap<br />

Starting: Intent { comp={org.kandroid.example.mymap/org.kandroid.example.mymap.MyMap} p p g p y p y p}} }<br />

1 2<br />

3<br />

unsigned<br />

Android<br />

Application<br />

(.apk)<br />

signed<br />

Android<br />

Application<br />

2<br />

(.apk)<br />

=> adb.exe<br />

adbd<br />

zipaligned<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

170


Application Signing : 애플리케이션 빌드,설치,런치 프로세스(2)<br />

Application Signing based on Custom KeyStore<br />

jarsigner.exe -verbose -keystore “debug.keystore" MyMap.apk androiddebugkey<br />

1<br />

unsigned<br />

Android<br />

Application<br />

(.apk)<br />

signed<br />

Android<br />

Application<br />

(.apk)<br />

adb.exe<br />

adbd<br />

1<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

171


질의및응답<br />

Q & A<br />

<strong>Korea</strong> Android Community- www.kandroid.org<br />

172

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!