모든 application은 root directory에 AndroidManifest.xml filed을 가지고 있다 이 파일은 application에 대한 주요한 정보와 System이 applicaiton의 코드를 실생할 수 있기 전에 시스템이 가지고 있어야 할 정보를 안드로이드 system에 제출한다.

  1) Application의 Java package
  2) Application의 Component를 기술한다.
  3) 어떤 process가 applicaiton component를 다룰 것인지 결정한다.
  4) application이 API의 protected parr를 접속하기 위한, 그리고 다른 Application과 연동하기 위한 permission을 선언한다.
  5) Applicaiton의 Component롸 연동하기 위해 필요한 permission을 선언한다.
  6) Application이 필요한 Android API의 minimum level 선언
  7) link 해야할 library 리스트
  8) 테스트를 위해 필요한 instrumentation class(?????) - 이건 잘 모르겠는데?

Structure of the Manifest File
<?xml version="1.0" encoding="utf-8"?>
<manifest>
    <uses-permission />
    <permission />
    <permission-tree />
    <permission-group />
    <instrumentation />
    <uses-sdk />
    <uses-configuration /> 
    <uses-feature /> 
    <supports-screens /> 
    <application>
        <activity>
            <intent-filter>
                <action />
                <category />
                <data />
            </intent-filter>
            <meta-data />
        </activity>
        <activity-alias>
            <intent-filter> . . . </intent-filter>
            <meta-data />
        </activity-alias>
        <service>
            <intent-filter> . . . </intent-filter>
            <meta-data/>
        </service>
        <receiver>
            <intent-filter> . . . </intent-filter>
            <meta-data />
        </receiver>
        <provider>
            <grant-uri-permission />
            <path-permission />
            <meta-data />
        </provider>
        <uses-library />
    </application>
</manifest>

Element, Attribute 등에 대한 상세 내역은 가이드 문서를 참조하세요.

Sample
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.example"
      android:versionCode="2"
      android:versionName="1.1">
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".HelloMapView"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
 
  <uses-library android:name="com.google.android.maps" /> ==> 외부 Library 사용
    </application>
    <uses-sdk android:minSdkVersion="3" />
 <uses-permission android:name="android.permission.INTERNET" /> ==> Network 사용을 위한 Permission
</manifest>

Posted by 피의복수

  안드로이드는 multi-process system으로 각 applicaiton은 자신의 process에서 실행한다. 대부분 Application과 System간의 security는 표준 Linux 기능 - Applicaiton에 할당되는 user and group ID - 을 통해 process level에서 수행된다. 부가적인 security 기능은 process가 수행하는 특정 업무에 대한 제한, data 접속에 대한 per-URI를 수행하는 "permission" mechanizm을 통해 제공된다.

Security Architecture
  안드로이드 security architecture의 주요 point는 application이 다른 applicatoin, OS 또는 user에 영향ㅇ르 미치는 어떠한 작업도 허용하지 않는 것이다.
Application의 process는 secure sandbox 이며, 다른 application을 중단 시킬수 없다. 다만 기존 sandbox에 제공되지 않는 부가적인 기능에 필요한 permission을 명백히 선언하는 경우는 제외이다. 이러한 permission은 다양한 방법으로 operating에의해 다루어 지는데, 인증을 기반으로 자동으로 허용/불허용하는 경우 또는 사용자에게 상기시키는 방법이 있다.
Application에 필요한 permission은 해당 Application에서 정적으로 선언되고, install전에 알려지며 그 후 변경되지 않는다.

Application Signing
  모든 안드로이드 Application(.apk file)은 private key를 가진 인증서로 sing되어야 한다. 이 인증서는 Application의 저작자를 식별해 준다. 인증서가 반드시 인증서 기관에서 sign될 필요는 없으며, 안드로이드 Application이 self-sing 인증서를 사용하는 것도 허용된다. 인증서는 단지 application 간의 신뢰있는 관계를 주기위해 사용되며, application이 설치될 수 있는지를 판단하기 위해 사용되는 것은 아니다.

User IDs and File Access
  Device에 설치되는 각각의 안드로이드 package(.apk file)은 자신의 unique Linix user ID를 가지며, 그것을 위한 sanbox를 생성하고, 가른 Applicaiton의 접근으로 부터 보호한다. user ID은 Device에 Applicaiton이 설치되는 경우에 할당을 받으며, Application의 생명주기 동안 존재하게 된다.

security에 대한 수행이 process level에서 이루어지므로 두개의 package의 코드가 동일한 procedd에서 실행될 수 없다.
하지만 동일한 user ID을 할당받기 위해 manifest file에 sharedUserId attribute를 사용할 수 있다. 이렇게 하면 두개의 package는 동일한 applicaiton으로 위급되어 동일한 user ID와 permission을 갖게된다. 동일한 서명으로 sign된 두개의 application만이 동일한 user ID를 사용할 수 있다.

  파일을 생성할때 MODE_WORLD_READABLE, MODE_WORLD_WRITABLE flag를 설정하면 다른 package가 같은 파일을 사용할 수 있게 된다.

Using Permission
  기본적으로 안드로이드 application은 permission이 없다.
Device의 protedted 기능을 사용하기 위해서는 manifest file에 하나 또는 그 이상의 <user-permission> tag를 사용하여 필요한 permission을 선언해 주어야 한다.
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.android.app.myapp" >

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

</manifest>

  Application 설치 시 application에서 필요로하는 permission은 package installer에 의해 권한이 부여된다. -  package installer는 permission을 선언한 application의 서명을 확인하거나 사용자의 입력을 통해 확인한다.


Posted by 피의복수

Content Provider는 Data를 저장하고 조회하며, 모든 Application에서 저장된 Data의 접근이 가능하도록 한다. Applicaiton간에 Data를 공유하는 유일한 방법이다.

안드로이드는 범용 data type(audio, image, video 등)에 대한 Content provider를 가지고 있으며 이것을 통해 Data를 조회할 수 있다.
Application의 Data를 public으로 하려면 ContentProvider의 subclass로 자신만의 Content Provider를 만들 수도 있고 기존의 provider에 Data를 추가할 수도 있다.

Content Provider Basics
  Content Provider가 어떻게 데이터를 저장하는지는 설계자의 몫이다. 하지만 모든 content provider는 provider를 조회하고 결과를 반환하는데 공통의 Interface를 구현해야 한다. (추가, 수정, 삭제 포함)
Client가 간접적으로 사용하는  Interface는 일반적으로 ContentResolver Object를 통한다. ContentResolver는 getContentResolver() method를 호출하여 얻을 수 있다.
ContentResolver cr = getContentResolver();

  Query가 시작되면 안드로이드 System은 Query의 Target인 Content Provider를 식별하고, 그것이 실행 중인지 확인한다.

1. The data model
  Content Provider는 database model의 단순한 table로 데이터를 진열하는데 각 row는 record이고 각 column은 특유의 타입과 의미를 가진 데이터이다.
모든 record는 table에서 record를 유일하게 식별하는 "_ID" field를 포함한다.
Query는 각 필드의 contents를 읽기 위해 record간, column간 이동할 수 있는 Cursor Object 를 반환한다. Cursor Object는 java의 ResultSet과 유사하게 각 데이터의 Type별로 method를 제공하므로, 각 필드의 데이터 Type을 알아야 한다.

2. URIs
  각 Content Provider는 data set을 유일하게 식별하는 public URI를 내놓으며, 다수의 data set을 제어하는 content provider는 각각에 대한 서로다른 URI를 내놓는다. 모든 URI는 "content://"로 시작하며, "content:"는 content provider에 의해 통제되는 data라는 것을 의미한다.
  만일 Content provider를 정의한다면, URI에 constant를 정의하고, client code를 단순화하며, 이 후 update를 명확히 하라. 안드로이드는 platform에 있는 모든 provider에 CONTENT_URI constant를 정의한다.
  URI constant는 content provider와의 모든 연동에 사용되며, 모든 ContentResolver method는 처음 argument로 URI를 받는다. 이를 통해 어떤 ContentResolver가 어떤 provider와 연동하는지 그리고 provider의 어떤 table이 target이 되는지 식별할 수 있다.

Querying a Content Provider
  Content Provider를 query하기 위해서는 provider를 식별할 수 있는 URI, 조회를 하는 데이터 필드명과 해당 필드의 데이터타입이 필요하다. 또한 특정 record를 조회하기위해서는 해당 record의 _ID가 필요하다.

1. Making a query
  Content Provider를 query하려면, ContentResolver.query()나 Activity.managedQuery() method를 사용한다. 두 method 모두 동일한 arguments를 사용하고 Cursor Object를 반환하지만, managedQuery() method는 Activity가 Cursor의 life cycle을 관리하도록 한다. managed Cursor는 Activit가 pause상태일 경우에는 unload 그리고 restart 상태일 경우 requery하는 것처럼 좀더 세밀하게 다룰 수 있다. 물론 unnmanaged cursor를 Acivity.startManagingCursor() method를 통해 managing을 시작할 수 있다.
query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder)
managedQuery(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder)

  1) query(), managedQuery()의 처음 argument는 provider URI이다. 하나의 record만 조회한다면 URI에 _ID value를 첨부하면 가능하다.

content://. . . ./23

또는
ContentUris.withAppendedId(), Uri.withAppendedPath()를 사용하라

  2) projection은 반환되는 data column명이다. 만일 null 이면 모든 column을 반환한다. 
  3) selection은 query에 대한 조건절을 명시하면 된다. 이는 SQL의 WHERE절에 해당한다. null인 경우 모든 rows가 반환된다. 단 URI에 _ID가 있는 경우는 제외
  4) selectionArgs는 java의 PreparedStatement와 유사하며, selection에 ?가 포함되는 경우에 값을 치환한다.
  5) sortOrder는 row의 order를 설정한다. SQL의 ORDER BY 절과 동일하다.
import android.provider.Contacts.People;
import android.database.Cursor;

// Form an array specifying which columns to return.
String[] projection = new String[] {
                             People._ID,
                             People._COUNT,
                             People.NAME,
                             People.NUMBER
                          };

// Get the base URI for the People table in the Contacts content provider.
Uri contacts =  People.CONTENT_URI;

// Make the query.
Cursor managedCursor = managedQuery(contacts,
                         projection, // Which columns to return
                         null,       // Which rows to return (all rows)
                         null,       // Selection arguments (none)
                         // Put the results in ascending order by name
                         People.NAME + " ASC");


2. What a query returns
  Query는 0 또는 그 이상의 database record를 반환하는데 각 column명, order 및 data type은 각 content provider에 지정되어 있다. 위에서 언급한것 처럼 모든 provider는 _ID column을 가지고 있고 이는 각 record의 unique numeric ID이며, _COUNT column처럼 반환하는 resord의 갯수를 줄 수도 있다.

3. Reading retrieved data
  query의 결과로 반환된 Cursor object을 통해 data를 접근할 수 있다. Java의 ResultSet class와 마찬가지로 Cursor도 각 data의 type에 따라 method를 제공하므로 - getString(), getInt() 등 - 조회하려는 table의 data type을 미리 알아야 한다.
query의 결과가 binary data를 반환한다면, data가 table에 직접 입력이 되어 있거나, 해당 data를 위한 table entry가 data를 얻기 위해 사용되는 URI일 수 있다. 일반적으로 적은 양의 데이터는 table에 직접 입력할 수 있으며, 이 경우 Cursor.getBlob() method를 사용하여 byte array를 가져올 수 있다.
만일 table entry가 content:URI로 구성되어 있으면, 직접 열고 읽기을 할 수 없으며 ContentResolver.openInputStream()을 사용하여 InputStream object를 얻은 후 사용한다.

Modifying Data
  Data의 추가,수정,삭제는 ContentResolver method를 사요하여야 하며, Content Provider에 따라 제약이 있을 수 있다.

1. Adding records
  새로운 record를 추가하기 위해서는 ContentValues object에 key-value를 설정하여 ContentResolver.insert() method를 사용한다. key는 table의 column명이 된다.
import android.provider.Contacts.People;
import android.content.ContentResolver;
import android.content.ContentValues;

ContentValues values = new ContentValues();

// Add Abraham Lincoln to contacts and make him a favorite.
values.put(People.NAME, "Abraham Lincoln");
// 1 = the new contact is added to favorites
// 0 = the new contact is not added to favorites
values.put(People.STARRED, 1);

Uri uri = getContentResolver().insert(People.CONTENT_URI, values);


2. Adding new values
  record가 존재하고, 새로운 value를 입력하거나 기존 정보를 수정려는 경우, 기존 정보에 대한 URI를 조회하고 key-value를 설정하여 ContentResolver.insert() method를 사용한다. (이미 위에서 특정 record를 조회할 수 있는 방법 - URI-을 설명한바 있다.
Uri phoneUri = null;
Uri emailUri = null;

// Add a phone number for Abraham Lincoln.  Begin with the URI for
// the new record just returned by insert(); it ends with the _ID
// of the new record, so we don't have to add the ID ourselves.
// Then append the designation for the phone table to this URI,
// and use the resulting URI to insert the phone number.
phoneUri = Uri.withAppendedPath(uri, People.Phones.CONTENT_DIRECTORY);

values.clear();
values.put(People.Phones.TYPE, People.Phones.TYPE_MOBILE);
values.put(People.Phones.NUMBER, "1233214567");
getContentResolver().insert(phoneUri, values);


3. Batch updating records
  record group을 batch로 update하려면 ContentResolver.update()를 사용한다. Batch Update란 SQL의 WHERE 절 없이 전체 table의 record를 대상으로 update하는 것을 의미한다.

4. Deleting a record
  Single record는 ContentResolver.delete() method을 사용하여 delete한다.
Multiple records는 동일한 method를 사용하지만 WHERE 절을 사용하여야 한다.

Creating a Content Provider
  Content Provider를 생성하려면
1) data 저장을 위해 System을 설정한다. 대부분 content provider는 안드로이드의 file storage method나 SQLite database를 사용해 data를 저장하지만 원하는 방식으로 데이터를 저장할 수 있다.
2) Data에 접근성을 제공하기 위해 ContentProvider를 상속한다.
3) Application을 위해 content provider를 manifest file에 선언한다.

1. Extending the ContentProvider class
ContentProvider의 subclass를 정의하고 ContentProvider에 정의된 6개의 acstract method를 구현하여야 한다.
query(), insert(), update(), delete(), getType, onCreate() 가 있다.

  query() method는 Cursor object를 반환해야 한다. Cursor는 그 자체가 interface이지만 안드로이드는 사용자가 사용할 수 있는 몇 개의 ready-made Cursor를 제공한다. 예를 들면 SALiteCursor등이 있다.
  ContentProvider method는 다른 process나 thread에서, 다양한 ContentResolver object로부터 호출될 수 있으므로 thread-safe 방식으로 구현되어야 한다.

  1) "CONTENT_URI"라는 이름으로 pulic static final Uri 변수를 정의한다. 정의된 URI는 Content Provider에서 다루어지게 될 "content:URI" 이며, unique한 string으로 선언되어야 한다.
public static final Uri CONTENT_URI =
               Uri.parse("content://com.example.codelab.transporationprovider");


  2) Column name을 정의한다. record의 id를  위해 "_ID"가 포함되어야 한다.
  3) 각 column의 data type을 정의한다.
  4) 새로운 data type을 다루고자 한다면, 새로운 MIME type을 정의하여야 한다.
  5) 대용량의 byte data를 넣고자 한다면, file system에 저장하고 이에 대한 URI string을 저장하여 client가 접근하여 사용할 수 있도록 한다.

2. Declaring the content provider
  안드로이드 System에 사용자가 정의한 Content Provider를 인지시키기 위해서는 Application manifest file에 <provider> element를 사용하여 선언한다.
 
<provider name="com.example.autos.AutoInfoProvider"
          authorities="com.example.autos.autoinfoprovider"
          . . . />
</provider>


Content URI Summary
  아래 예제를 보면서 Content URI에 대해 요약 설명하도록 한다.

  A. Data가 Content Provider에 의해 제어되는 것을 지시하는 prefix
  B. URI의 Authority 부분으로 Content Provider를 식별한다.
  C.  Content Provider가 요청되고 있는 data의 종류를 결정하기 위해 사용되는 path.
  D. 특정 record의 ID.(생략 가능함. 생략하는 경우 전체 record)

Posted by 피의복수

안드로이드의 모든 Application의 data는 자신만이 사용할 수 있도록 한다. (처음 안드로이드에 대해 설명할 때 Linux로 되어 있고 user ID를 가진다고 언급한 적이 있다. 이것과 연관지어 보면 쉽게 이해될 것이다.)
  하지만 다른 Application에 private data를 노출하도록 표준 방법을 제공하고 있다. (무엇을 통해서? 이전에 ContentProvider라는 것에 대해 설명한 적이 있다.)
안드로이드는 표준 data type에 대한 여러개의 content provider를 제공하고 있다.

안드로이드가 제공하는 데이터 저장과 조회를 위한 4가지의 방안을 아래에 설명하려고 한다.

Preferences
  Preference는 원시적 data type의 key-value을 저장하고 검색하는 간단한 방법이다.
Context.getSharedPreferences()를 호출하면 된다. 동일한 Application에서 서로 다른 Component와 데이터를 공유하기 위해서는 preference에 name을 부여하고, 그렇지 않을 경우는 name 없이 Activity.getPreferences()를 사용한다.
Application 간의 preference를 공유할 수는 없다 - 단 Content provider를 사용하면 가능

Files
  단말이나 삭제가능한 저장장치에 file을 저장할 수 있으며, 기본적으로 다른 Application에서는 접근이 불가능하다.

File에서 Data를 읽기위해서는 Context.openFileInput() method를 사용하고, local name과 file path를 전달한다. 해당 method는 표준 Java의 FileInputStream을 반환하므로 이 후 사용을 Java와 동일하다.
Data를 쓰기 위해서는 Context.openFileOutput() method를 사용하고 name과 path를 전달하며, FileoutputStream이 반환된다.

Application Compile 시에 static File을 package에 추가하려면, /res/raw/myDataFile에 저장하고, Resources.OpenRawResource(R.raw.myDataFile)을 사용하여 InputStream을 얻을 수 있다.

Database
  안드로이드는 SQLite database를 생성하고 사용할 수 있는 API를 제공하며, 다른 방식과 마찬가지로 생성한 Application에만 접근이 허용된다.
SQLiteDatabase Object를 사용하며 이를 통해 Database를 생성하고 query를 만들고 data를 관리할 수 있다.

Network
  java.net.*, android.net.* 를 사용하여 Network을 활용할 수도 있다.







Posted by 피의복수

앞에서 설명했듯이 Application의 core component-activity, service and broadcast receiver-는 Intent라고 불리는 메시지를 통해 활성화 된다.
Intent messaging은 동일한 또는 다른 Application의 component 간의 최근 run-time binding에 대한 기능(facility)이다.
intent 그 자체는 - Intent object- 수행할 업무의 추상정인 description을 가지고 있는 passive data structure 이다.

Application Core Component 별로 Intent는 아래와 같은 경우에 사용된다.
1. Intent Object는 activity를 실행하거나 새로운 일을 하고 있는 activity를 얻기위해 Context.startActivity()나 Activity.startActivityForResult()에 전달된다.
2. Intent는 Service를 초기화하거나 진행중인 service에 새로운 지시를 전달하기 위해 Context.startService()에 전달된다.
3. broadcast method로 전달되는 Intent는 모든 관계된 broadcast receiver에 전달된다.

위의 각각의 경우에 대해 안드로이드는 intent에 상응하는 적당한 activity, service 또는 broadcast receiver를 찾고, 필요하다면 그것들을 instance로 만든다.
이러한 messaging system에 대해서는 중복이 없다. 즉 startActivity()로 전달된 Intent는 Activity에만 전달이 되며, service나 broadcast receiver에 전달되지 않는다는 의미이다.

Intent Objects
  Intent Object는 정보의 묶음이다.
Intent는 다음과 같은 정보를 포함한다.
1. Component name
  Intent를 다루는 Component name으로 ComponentName Object(fully qualified class name like com.example.HelloWorld)과 application manifest file에 설정된 package name 이다. - Component name의 package와 mainfest에 설정된 package는 일치하지 않아도 된다.
Component name은 optional이며 설정되어 있으면 intent object는 명시된 class의 instance에 전달되고, 설정되어있지 않으면 안드로이드는 Intent의 다른 정보를 적절한 target을 정하기 위해 사용한다.

  Compoennt name은 setComponent(), setClass()나 setClassName() method를 통해 설정하며, getComponent() method를 통해 조회된다.

2. Action
  수행될 Action의 string naming.
Intent class는 아래와 같이 다양한 action constants를 정의한다.
 Constant  Target component  Action
 ACTION_CALL  activity  Initiate a phone call
 ACTION_EDIT  activity  Display data for the user to edit
 ACTION_MAIN  activity  Start up as the initial activity of a task, with no data input and no returned output
 ACTION_SYNC  activity  Synchronize data on a server with data on the mobile device
 ACTION_BATTERY_LOW  broadcast receiver  A warning that the battery is low
 ACTION_HEADSET_PLUG  broadcast receiver  A headset has been plugged into the device, or unplugged from it
 ACTION_SCREEN_ON  broadcast receiver  The screen has been turned on
 ACTION_TIMEZONE_CHANGED  broadcast receiver  The setting for the time zone has changed
     
  Intent class에 기정의된 action의 list에 대한 설명이 있으며 다른 action은 안드로이드 API에 정의되어 있다. 또한 사용자 Application의 Component를 활성화가기 위해 자신만의 action string을 정의할 수도 있으며, 이 경우 application의 package를 포함해야 한다.

Intent의 Action은 setAction() method를 통해 설정하며, getAction() method를 통해 조회된다.

3. Data
  Intent의 Data는 수행할 data의 URI와 그 data의 MIME type이다. 서로 다른 Action은 서로 다른 종류의 Data와 쌍으로 이루어져 있다. 예를 들어 Action이 ACTION_EDIT라면 Data는 수정될 문서의 URL를 포함하며, ACTION_CALL일라면 "tel:전화번호"로 이루어 진다.
  Intent를 Component와 매칭시키는 경우 그 Data의 Type을 인지하는 것이 중요하다. 예를 들면 audio type은 audio를 출력하는 Component로 매칭을 시켜야 하기 때문이다.
대부분의 경우 Data type은 URI를 통해 추정되는데, 예를 들어 "content:" URI는 Data가 단말에 위치하고 ContentProvider에 의해 제어된다는 것을 알 수 있다. 하지만 Data type은 Intent Object에서 명확히 설정될 수 있다.
Intent의 Data는 setData() method를 통해, MIME type은 setType() method를 통해 설정할 수 있으며, setDataAndType() method를 통해 한 번에 설정될 수 있으며, getData(), getType() method를 통해 조회할 수 있다.

4. Category
  Category는 Intent를 다루는 Component의 종류에 대해 부가적인 정보를 포함하는 string이다.
Intent Object에는 몇 개의 category 정보가 있을 수 있는데, Action과 마찬가지로 Intent class는 몇 개의 category constants를 가지고 있다.
 Constant  Description
 CATEGORY_BROWSABLE  The target activity can be safely invoked by the browser to display data referenced by a link — for example, an image or an e-mail message.
 CATEGORY_GADGET  The activity can be embedded inside of another activity that hosts gadgets
 CATEGORY_HOME  The activity displays the home screen, the first screen the user sees when the device is turned on or when the HOME key is pressed.
 CATEGORY_LAUNCHER  The activity can be the initial activity of a task and is listed in the top-level application launcher
 CATEGORY_PREFERENCE  The target activity is a preference panel

Intent Object에 Category를 추가하기 위해 addCategory(), 이전에 추가된 Category를 삭제하기 위해 removeCategory() mehotd를 사용하며, 현재 Object의 모든 Category를 조회하기 위해 getCategories() method를 사용한다.

5. Extras
  Intent를 다룰 Component에 전달되는 부가적인 정보의 key-value.
몇몇 Action들이 특정한 종류의 data URI와 쌍으로 구성되듯이, 몇 몇은 특정 Extras와 쌍으로 구성된다. 예를 들어 ACTION_TIMEZONE_CHANGED intent는 새로운 Timezone을 나타내는 "time-zone" extra를 가지고 있다. 또한 ACTION_HEADSET_PLUG Action 은 현재 headset이 plug되어 있는지를 나타내는 "state" extra를 가지고 있다. 만일 사용자가 정의하는 SHOW_COLOR라는 Action이 있다면 color value는 extra key-value를 설정하게 될 것이다.

  Extras는 putExtras()와 getExtras() method 를 사용하여 extras를 설정하고 조회할 수 있다.

6. Flags
  Intent class에 정의되어 있는 Flag를 참조

Intent Resolution
  Intent는 두가지의 Group으로 구분할 수 있다.
1. Explicit Intent
  Component name으로 target component를 명시한다. 일반적으로 다른 Applicaiton의 개발자에세 Component name이 공개되지 않으므로, explicit intents는 전형적인 application internal message이다.

2. Implicit Intent
  Target component를 명시하지 않으며, 다른 Application의 component를 활성화하기위해 사용된다.

안드로이드는 명시된 target class의 instance에 explicit intent를 전달한다. Component name이 중요하다.
target 이 명시되지 않는 경우 안드로이드는 intent를 다룰 가장 적합한 Component를 찾아야 한다. 이 경우는 Intent Object를 Intent filter와 비교함으로써 진행된다. intent filter는 잠재적으로 intent를 수신할 수 있는 Component와 관련된 structure이다. Filter는 component의 특성을 공시하고 그것이 드룰 수 있는 intent를 정한다.
  Component가 filter를 가지지 않으면 이는 explicit intent만을 수용하겠다는 의미이다.

Action, data, category만이 intetn filter에서 적용할 수 있고, extras나 flag는 resolving의 대상이 되지 않는다.

Intent filters
  어떤 implicit intent를 다룰수 있는지 시스템에 알리기 위해 Activity, Service 및 Broadcast Receiver는 하나 또는 그 이상의 intent filter를 가진다. 각 filter에는 component의 특성, 수신하려는 intent의 종류를 기술한다.
explicit intent는 어떤 것이 포함되어 있던간에 target Component에 전달된다. 하지만 implicit intent는 filter에 정의된 component로만 전달된다.

  Intent Filter는 IntentFilter class의 instance이다. 하지만 안드로이드 System은 component를 launch하기 전에 해당 Component에 대한 특성을 알아야 하기에 Source code가 아니라 manifest file에 intent filter를 설정한다. (단 broascast receiver의 경우는 동적으로 등록되기 때문에 제외된다.)

Posted by 피의복수
<< PREV : [1] : [2] : [3] : [4] : [5] : [6] : [7] : [8] : NEXT >>

BLOG main image
일에 필요한 자료 by 피의복수

카테고리

분류 전체보기 (40)
프로그램이야기 (38)
끄적끄적 (1)
취미 (0)
서비스이야기 (1)
빅데이터 (0)

최근에 올라온 글