'개발/모바일OS(안드로이드,아이폰,윈도모바일등)'에 해당되는 글 59건

  1. 2010.01.22 A Visual Guide to Android GUI Widgets
  2. 2010.01.21 안드로이드 에뮬레이터에 가상의 SD카드 마운트시키기
  3. 2010.01.20 Web View 샘플구현 8
  4. 2010.01.19 안드로이드 ListActivity 링크소스 10
  5. 2010.01.18 [Source] SD 카드에 저장되어 있는 비디오 목록 출력및 비디오 실행하기 11
  6. 2010.01.18 안드로이드 암시적 인텐트(Implicit Intent)를 사용해보자!
  7. 2010.01.15 About Android 2
  8. 2010.01.15 Android Run-Time 분석
  9. 2010.01.14 Android Initialization Process 1
  10. 2010.01.14 iPhone OS Architecture
2010. 1. 22. 11:06

A Visual Guide to Android GUI Widgets





For rapid development of your user interfaces try DroidDraw

2010. 1. 21. 14:04

안드로이드 에뮬레이터에 가상의 SD카드 마운트시키기





에뮬레이터 실행 버튼 클릭
그러면 에뷸레이터가 실행된다.(꼭 실행해야 다음이 진행된다.)


이렇게 설정을 끝낸 후, 에뮬레이터를 실행시키면 가상 SD카드가 마운트 된 채로 에뮬레이터가 실행됩니다.
그럼, 이 SD카드에 파일을 넣어볼까요?



이클립스에서 DDMS를 실행시킨 후, File Explorer탭을 클릭해보면 아래와 같은 아이콘이 보이실겁니다. 에뮬레이터에 파일을 넣어야하니 Push a file onto the device를 눌러줍니다.




등록후 화면(꼭 영어로만된 파일 등록해야함)

 

자, 저렇게 해주면 이렇게! 뿅! 들어가있는 것을 볼 수 있습니다.
자, 그럼 이제 이 파일을 안드로이드 에뮬레이터에서 들어볼까요?
파일을 추가했으니, 바로 음악을 듣기 전에 Dev Tools의 Media Scanner를 실행해서 파일을 인식시켜주어야 합니다.

Media Scanner가 새로 추가된 파일을 검색중인 화면.


검색이 끝났다면, 음악을 들어볼까요?
Music을 눌러보시면, 다음과 같이 음악이 추가되어있는 것을 보실 수 있을 겁니다!


음악 파일 뿐만 아니라 다른 파일을 넣을 떄에도 지금과 동일한 과정으로 수행하시면 됩니다. :)

p.s : 이걸 통해서 삭막한 개발환경을 조금이나마 업 시킬수 있겠네요~ :)

2010. 1. 20. 12:45

Web View 샘플구현





시나리오

아래와 같은 뷰를 작성합니다.
초기 화면은 구글 페이지를 디스플레이합니다. 
앞으로, 뒤로 이동할 수 있어야 합니다.

 
 


1. 프로젝트 생성
프로젝트, 애플리케이션: WebViewingApp
패키지: android15.samples
액티비티: WebViewingStoryboard

완성된 프로젝트 파일은 아래에 첨부합니다.


2. 메인 폼 작성

2.1 전체에 대한 레이아웃 구상
웹뷰가 화면 전체 영역을 차지합니다.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical">
    <WebView
        android:id="@+id/webview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
    />
</LinearLayout>


웹뷰에 대한 상세사항은 다음 링크를 참조합니다.
http://android15.tistory.com/164


3. 애플리케이션 초기화면
3.1 웹뷰를 다루는 멤버를 선언합니다.

WebView _webview;

3.2 onCreate 재정의
웹뷰가 자바스크립트를 사용하도록 설정하고, 구글페이지를 로드합니다. 
onCreate에 다음을 추가합니다. 
_webview = (WebView) findViewById(R.id.webview);
_webview.getSettings().setJavaScriptEnabled(true);
_webview.loadUrl("http://www.google.com");

3.3 인터넷 접근허용
웹뷰는 인터넷을 사용해야 합니다. 인터넷은 접근허용을 받아야 하는 것입니다. 
매니페스트 파일(AndroidMenifest.xml)을 열고, <menifest> 요소에 다음을 포함합니다.
<uses-permission android:name="android.permission.INTERNET" />

3.3 애플리케이션을 수행합니다.
다 된 것처럼 보입니다.
그러나 웹페이지의 링크를 클릭해보세요.
우리의 웹뷰가 링크된 페이지를 보여주는 것이 아니라, 안드로이드에 기본으로 설정된 웹 브라우저가 해당 페이지를 보여줍니다.


4. 링크된 페이지가 우리의 웹뷰안에서 로드되게 하기
4.1 웹뷰클라이언트 재정의(WebViewClient)

웹뷰클라이언트 클래스를 확장하는 클래스를 작성하고, shouldOverrideUrlLoading 메소드를 재정의합니다.
true를 리턴함으로 우리의 웹뷰에서 URL을 처리했음을 알립니다.
private class HelloWebViewClient extends WebViewClient {
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        view.loadUrl(url);
        return true;
    }
}

4.2 웹뷰에 웹뷰클라이언트 설정
Url을 로드하기 앞서, 웹뷰클라이언트를 설정합니다.
onCreate 부분을 아래와 같이 수정합니다. 
...
_webview.setWebViewClient(new HelloWebViewClient());
_webview.getSettings().setJavaScriptEnabled(true);
_webview.loadUrl("http://www.google.com");

4.3 애플리케이션을 수행해봅니다.
위와 같이 했을 경우, 원하는 웹페이지를 로드한 웹뷰가 나타나는 것이 아니라 바탕화면이 검정색으로 보입니다. 바탕화면이 검정색으로 보이는 것은 검정색으로 배경이 설정된 바탕 윈도우만 보이고, 그 위에 보여야할 뷰들이 보이지 않기 때문입니다.
웹뷰를 설정했는데, 보이지 않는다는 것은 어떤 이유인지는 모르지만 웹뷰의 크기가 0이 되었거나 웹뷰를 포함하는 부모의 크기가 0이 되었다는 것을 의미합니다.  
헬로뷰 예에서, 웹뷰의 부모인 레이아웃의 너비와 높이가 'wrap_content'로 설정되어 있으니, 만약 레이아웃이 웹뷰의 크기를 측정할 때 웹뷰의 크기가 0으로 계산된다면 부모 레이아웃의 크기도 0이 됩니다. 

4.3.1  이 부분이 의심스러우니 레이아웃의 너비와 높이를 'fill_parent'로 설정해 봅니다.
제대로 나옵니다.
정말 웹뷰클라이언트를 설정했을 때 웹뷰의 크기가 커짐에도 불구하고, 레이아웃의 크기가 0이 되는 것인지는 안드로이드 소스코드를 까봐야겠네요. 


5. 앞으로, 뒤로 이동에 대한 시나리오 구현
왼쪽 키를 누르면 뒤로, 오른쪽 키를 누르면 앞으로 가게 합니다.
다음과 같이 HelloWebViewClient의 shouldOverrideKeyEvent를 재정의합니다. 
@Override
public boolean shouldOverrideKeyEvent (WebView view, KeyEvent event) {
    int keyCode = event.getKeyCode();
    if ((keyCode == KeyEvent.KEYCODE_DPAD_LEFT) && _webview.canGoBack()) {
        _webview.goBack();
        return true;
    }
    else if ((keyCode == KeyEvent.KEYCODE_DPAD_RIGHT) && _webview.canGoForward()) {
        _webview.goForward();
        return true;
    }
    return false;
}



2010. 1. 19. 12:58

안드로이드 ListActivity 링크소스





SelectCurrency.java
AnalogClock
<AnalogClockid="@+id/clock1"android:layout_width="wrap_content"android:layout_height="wrap_content"/>
Button
<Button id ="@+id/button1" android:text="Label" android:layout_width="fill_parent" android:layout_height="fill_parent"/><Button id ="@+id/button2" android:text="Label" android:layout_width="fill_parent" android:layout_height="fill_parent" android:typeface="serif"/><Button id ="@+id/button3" android:text="Label" android:layout_width="fill_parent" android:layout_height="fill_parent" android:textStyle="bold_italic"/>
CheckBox
<CheckBox id="@+id/plain_cb" android:text="Plain" android:layout_width="wrap_content" android:layout_height="wrap_content"/><CheckBox id="@+id/serif_cb" android:text="Serif" android:layout_width="wrap_content" android:layout_height="wrap_content" android:typeface="serif"/><CheckBox id="@+id/bold_cb" android:text="Bold" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textStyle="bold"/><CheckBox id ="@+id/italic_cb" android:text="Italic" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textStyle="italic"/>
DatePicker
<DatePicker android:layout_width="wrap_content" android:layout_height="wrap_content" >...// Required Java init code:DatePicker dp =      (DatePicker)this.findViewById(R.id.widget27);// for example init to 1/27/2008, no callback dp.init(2008, 0, 27, Calendar.SUNDAY, null);  ...
DigitalClock
<DigitalClock id="@+id/digitalclock"  android:layout_width="wrap_content"  android:layout_height="wrap_content"/>
EditText
<EditText id ="@+id/edittext1" android:text="EditText 1" android:layout_width="wrap_content" android:layout_height="wrap_content"/><EditText id ="@+id/button2" android:text="(206)555-1212" android:layout_width="wrap_content" android:layout_height="wrap_content" android:typeface="serif" android:phoneNumber="true"/><EditText id ="@+id/password" android:text="SuperSecret" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textStyle="bold_italic" android:password="true"/>
Gallery
<Gallery  id="@+id/gallery"  android:layout_width="wrap_content"  android:layout_height="wrap_content"/>
ImageButton
<ImageButton id="@+id/imagebutton"  android:src="@drawable/brush"  android:layout_width="wrap_content"  android:layout_height="wrap_content"/>
ImageView
<ImageView id="@+id/imagebutton"  android:src="@drawable/brush"  android:layout_width="wrap_content"  android:layout_height="wrap_content"/>
ProgressBar
<ProgressBar id="@+id/progress"  android:layout_width="wrap_content"  android:layout_height="wrap_content"/>
RadioButton
<RadioGroupid="@+id/widget1"android:layout_width="wrap_content"android:layout_height="wrap_content"xmlns:android="http://schemas.android.com/apk/res/android"android:orientation="vertical"><RadioButtonid="@+id/widget2"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="Plain"android:checked="false"android:layout_gravity="left"android:layout_weight="0"></RadioButton><RadioButtonid="@+id/widget3"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="Serif"android:checked="true"android:layout_gravity="left"android:layout_weight="0"android:typeface="serif"></RadioButton><RadioButtonid="@+id/widget25"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="Bold"android:checked="false"android:layout_weight="0"android:layout_gravity="left"android:textStyle="bold"></RadioButton><RadioButtonid="@+id/widget24"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="Bold & Italic"android:checked="false"android:layout_weight="0"android:layout_gravity="left"android:textStyle="bold_italic"></RadioButton></RadioGroup>
Spinner
<Spinner id="@+id/widget1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:drawSelectorOnTop="false"/>
TextView
<TextView id="@+id/plain" android:text="Plain" android:layout_width="wrap_content" android:layout_height="wrap_content"/><TextView id="@+id/serif" android:text="Serif" android:layout_width="wrap_content" android:layout_height="wrap_content" android:typeface="serif"/><TextView id="@+id/bold" android:text="Bold" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textStyle="bold"/><TextView id ="@+id/italic" android:text="Italic" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textStyle="italic"/>
TimePicker
<TimePicker id="@+id/widget3" android:layout_width="wrap_content" android:layout_height="wrap_content"/>

package com.sh;

import android.app.Activity;
import android.os.Bundle;

import java.util.Currency;
import java.util.Locale;

import android.app.ListActivity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

public class SelectCurrency extends ListActivity {

 String[] countries ={"aaa","bbb","ccc","ddd","eee","fff"};
 Locale[] ll;

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

  ll = Locale.getAvailableLocales();
  //countries = new String[ll.length];
  //int i = 0;
  //for (Locale loc : ll) {
  // countries[i] = loc.getDisplayCountry();
  // i++;
  //}

  setListAdapter(new ArrayAdapter<String>(this,
    android.R.layout.simple_list_item_1, countries));
  getListView().setTextFilterEnabled(true);
 }

 @Override
 protected void onListItemClick(ListView l, View v, int position, long id) {
  super.onListItemClick(l, v, position, id);
  Context context = getApplicationContext();
  Toast.makeText(context, "Country selected: " + countries[position] +":position="+position,
    Toast.LENGTH_LONG).show();
  Intent intent = new Intent(SelectCurrency.this, PokerWinnings.class);
  startActivity(intent);
 }

}

 

PokerWinnings.java

 package com.sh;

import android.app.Activity;
import android.os.Bundle;

public class PokerWinnings extends Activity {
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  this.setContentView(R.layout.pokerwinning);
 }
}

main.xml
 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<TextView 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/hello"
    />
</LinearLayout>
pokerwinning.xml
 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<TextView 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/hello"
    />
</LinearLayout>

AndroidManifest.xml

 <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.sh"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".SelectCurrency"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
     <activity android:label="@string/app_name" android:name=".PokerWinnings">
      <intent-filter>
       <category android:name="android.intent.category.LAUNCHER" />
   </intent-filter>
  </activity>
    </application>
    <uses-sdk android:minSdkVersion="6" />

</manifest>


strings.xml
 <?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="hello">Hello World, SelectCurrency!</string>
    <string name="app_name">리스트클릭테스트</string>
</resources>


화면
 
 크릭후..
 

2010. 1. 18. 16:31

[Source] SD 카드에 저장되어 있는 비디오 목록 출력및 비디오 실행하기






The folowing example used to list all the video files stored in SDcard and you can
play the video by selecting the file from list.

AndroidManifest.xml
--------------------
<?xml version="1.0" encoding="utf-8"?>
< manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="sample.video" android:versionCode="1" android:versionName="1.0.0">
      < uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />
      < application android:icon="@drawable/icon" android:label="@string/app_name">
            < activity android:name=".VideoActivity" android:label="@string/app_name">
                  < intent-filter>
                        < action android:name="android.intent.action.MAIN" />
                        < category android:name="android.intent.category.LAUNCHER"/>
                  < /intent-filter>
            </activity>
            < activity android:name=".ViewVideo">
                  < intent-filter>
                        < action android:name="android.intent.action.VIEW" />
                        < category android:name="android.intent.category.DEFAULT" />
                  </intent-filter>
            </activity>
      </application>
</manifest>


main.xml
--------
<?xml version="1.0" encoding="utf-8"?>
< LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:orientation="vertical" android:layout_width="fill_parent"
      android:layout_height="fill_parent">
      < ListView
            android:id="@+id/PhoneVideoList"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"/>
</LinearLayout>

VideoActivity.java
-------------------
package sample.video;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;

public class VideoActivity extends Activity {
      private Cursor videocursor;
      private int video_column_index;
      ListView videolist;
      int count;

      /** Called when the activity is first created. */
      @Override
      public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            init_phone_video_grid();
      }

      private void init_phone_video_grid() {
            System.gc();
            String[] proj = { MediaStore.Video.Media._ID,
MediaStore.Video.Media.DATA,
MediaStore.Video.Media.DISPLAY_NAME,
MediaStore.Video.Media.SIZE };
            videocursor = managedQuery(MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
proj, null, null, null);
            count = videocursor.getCount();
            videolist = (ListView) findViewById(R.id.PhoneVideoList);
            videolist.setAdapter(new VideoAdapter(getApplicationContext()));
            videolist.setOnItemClickListener(videogridlistener);
      }

      private OnItemClickListener videogridlistener = new OnItemClickListener() {
            public void onItemClick(AdapterView parent, View v, int position,
long id) {
                  System.gc();
                  video_column_index = videocursor
.getColumnIndexOrThrow(MediaStore.Video.Media.DATA);
                  videocursor.moveToPosition(position);
                  String filename = videocursor.getString(video_column_index);
                  Intent intent = new Intent(VideoActivity.this, ViewVideo.class);
                  intent.putExtra("videofilename", filename);
                  startActivity(intent);
            }
      };

      public class VideoAdapter extends BaseAdapter {
            private Context vContext;

            public VideoAdapter(Context c) {
                  vContext = c;
            }

            public int getCount() {
                  return count;
            }

            public Object getItem(int position) {
                  return position;
            }

            public long getItemId(int position) {
                  return position;
            }

            public View getView(int position, View convertView, ViewGroup parent) {
                  System.gc();
                  TextView tv = new TextView(vContext.getApplicationContext());
                  String id = null;
                  if (convertView == null) {
                        video_column_index = videocursor
.getColumnIndexOrThrow(MediaStore.Video.Media.DISPLAY_NAME);
                        videocursor.moveToPosition(position);
                        id = videocursor.getString(video_column_index);
                        video_column_index = videocursor
.getColumnIndexOrThrow(MediaStore.Video.Media.SIZE);
                        videocursor.moveToPosition(position);
                        id += " Size(KB):" + videocursor.getString(video_column_index);
                        tv.setText(id);
                  } else
                        tv = (TextView) convertView;
                  return tv;
            }
      }
}



ViewVideo.java
---------------
package sample.video;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.MediaController;
import android.widget.VideoView;

public class ViewVideo extends Activity {
      private String filename;
      @Override
      public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            System.gc();
            Intent i = getIntent();
            Bundle extras = i.getExtras();
            filename = extras.getString("videofilename");
            VideoView vv = new VideoView(getApplicationContext());
            setContentView(vv);
            vv.setVideoPath(filename);
            vv.setMediaController(new MediaController(this));
            vv.requestFocus();
            vv.start();
      }
}
2010. 1. 18. 15:48

안드로이드 암시적 인텐트(Implicit Intent)를 사용해보자!






이번 강좌에서는 예제를 통해 여러 암시적 인텐트를 사용하는 방법에 대해 알아보도록 하겠습니다. 이번 예제에서 사용해볼 암시적 인텐트들은 다음과 같습니다.

  • 전화번호 입력(Dial)
  • 전화 걸기 (Call)
  • 오디오 파일 불러오기
  • 전화번호부 데이터 불러오기

예제 어플리케이션은 각 버튼를 누르면 해당 인텐트를 실행하도록 되어있으며, 예제에서 사용된 코드는 다음과 같습니다.

[IntentTester.java]

01.package com.androidhuman.IntentTester;
02.  
03.package com.androidhuman.IntentTester;
04.  
05.import android.app.Activity;
06.import android.content.Intent;
07.import android.net.Uri;
08.import android.os.Bundle;
09.import android.util.Log;
10.import android.view.View;
11.import android.view.View.OnClickListener;
12.import android.widget.Button;
13.  
14.public class IntentTester extends Activity {
15.    /** Called when the activity is first created. */
16.    @Override
17.    public void onCreate(Bundle savedInstanceState) {
18.        super.onCreate(savedInstanceState);
19.        setContentView(R.layout.main);
20.          
21.        Button callButton = (Button)findViewById(R.id.callbutton);
22.        Button dialButton = (Button)findViewById(R.id.dialButton);
23.        Button getAudioButtonWithChooser = (Button)findViewById(R.id.getAudioButtonWithChooser);
24.        Button getAudioButton = (Button)findViewById(R.id.getAudioButton);
25.        Button getContactsButton = (Button)findViewById(R.id.getContactsButton);
26.          
27.        callButton.setOnClickListener(new OnClickListener(){
28.  
29.            public void onClick(View v) {
30.                Intent i = new Intent(Intent.ACTION_CALL);
31.                i.setData(Uri.parse("tel:0101234567"));
32.                startActivity(i);
33.            }
34.              
35.        });
36.          
37.        dialButton.setOnClickListener(new OnClickListener(){
38.  
39.            public void onClick(View v) {
40.                Intent i = new Intent(Intent.ACTION_DIAL);
41.                i.setData(Uri.parse("tel:0101234567"));
42.                startActivity(i);
43.            }
44.              
45.        });
46.          
47.        getAudioButton.setOnClickListener(new OnClickListener(){
48.  
49.            public void onClick(View v) {
50.                Intent i = new Intent(Intent.ACTION_GET_CONTENT);
51.                i.setType("audio/*");
52.                startActivityForResult(i, 0);
53.            }
54.              
55.        });
56.                  
57.       getAudioButtonWithChooser.setOnClickListener(new OnClickListener(){
58.  
59.            public void onClick(View v) {
60.                Intent i = new Intent(Intent.ACTION_GET_CONTENT);
61.                i.setType("audio/*");
62.                startActivityForResult(Intent.createChooser(i, "Select Audio Source..."), 0);
63.                }
64.                      
65.            });         
66.          
67.          
68.        getContactsButton.setOnClickListener(new OnClickListener(){
69.  
70.            public void onClick(View v) {
71.                Intent i = new Intent(Intent.ACTION_PICK);
72.                i.setData(Uri.parse("content://contacts/phones"));
73.                startActivityForResult(i,0);
74.            }
75.              
76.        });
77.    }
78.      
79.    protected void onActivityResult(int requestCode, int resultCode, Intent data){
80.        super.onActivityResult(requestCode, resultCode, data);
81.        if(resultCode == RESULT_OK){
82.            Log.i("IntentTester", data.getData().toString());
83.        }
84.    }
85.}

[main.xml]

01.<?xml version="1.0" encoding="utf-8"?>
02.<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
03.    android:orientation="vertical"
04.    android:layout_width="fill_parent"
05.    android:layout_height="fill_parent"
06.    >
07.  
08.<Button android:layout_height="wrap_content" 
09.    android:id="@+id/callbutton" 
10.    android:layout_width="fill_parent" 
11.    android:text="action : ACTION_CALL / data : tel:0101234567"></Button>
12.  
13.<Button android:layout_height="wrap_content" 
14.    android:layout_width="fill_parent" 
15.    android:id="@+id/dialButton" 
16.    android:text="action : ACTION_DIAL / data : tel:0101234567"></Button>
17.  
18.<Button android:layout_height="wrap_content" 
19.    android:layout_width="fill_parent" 
20.    android:id="@+id/getAudioButton" 
21.    android:text="action : ACTION_GET_CONTENT / type : audio/*"></Button>
22.  
23.<Button android:layout_height="wrap_content" 
24.    android:layout_width="fill_parent" 
25.    android:text="action : ACTION_GET_CONTENT / type : audio/* / with Chooser" 
26.        anddroid:id="@+id/getAudioButtonWithChooser"></Button>
27.  
28.<Button android:layout_height="wrap_content" 
29.    android:layout_width="fill_parent" 
30.    android:id="@+id/getContactsButton" 
31.    android:text="action : ACTION_PICK / data : content://contacts/phones"></Button>
32.</LinearLayout>

IntentTester 액티비티는 데이터를 받아오는 인텐트를 사용했을 때 데이터를 받아오는 것을 확인하기 위해 onActivityResult() 메소드에서 받은 데이터를 LogCat을통해 표시해주도록 하고 있습니다.



또한, 예제에서 전화번호 입력, 전화 걸기 및 주소록에서 데이터베이스를 읽어야 하므로 이에 따른 권한이 필요합니다. 메니페스트 파일에 해당 권한을 추가해주도록 합시다.



우선, 전화번호를 입력(Dial)하는 인텐트와 전화를 거는 인텐트부터 살펴보겠습니다. 

01.callButton.setOnClickListener(new OnClickListener(){
02.  
03.            public void onClick(View v) {
04.                Intent i = new Intent(Intent.ACTION_CALL); // 전화를 거는 액션
05.                i.setData(Uri.parse("tel:0101234567")); // 전화번호를 인텐트에 넣어줍니다.
06.                startActivity(i); // 해당 인텐트를 처리하는 액티비티 (Dialer) 실행
07.            }
08.              
09.        });
10.          
11.        dialButton.setOnClickListener(new OnClickListener(){
12.  
13.            public void onClick(View v) {
14.                Intent i = new Intent(Intent.ACTION_DIAL); // 전화번호를 입력하는 액션
15.                i.setData(Uri.parse("tel:0101234567")); // 전화번호를 인텐트에 추가합니다.
16.                startActivity(i); // 해당 인텐트를 처리하는 액티비티 (Dialer) 실행
17.            }
18.              
19.        });


전화를 거는 동작은 액션으로 ACTION_CALL을 가지고, 전화번호를 입력하는 동작은 액션으로 ACTION_DIAL을 가지며, 두 액션 모두 데이터(Data)로 전화를 걸거나 입력할 번호를 필요로 합니다. 보통, 데이터에는 실제 데이터가 아닌 데이터의 주소(URI; Uniform Resource Identifier)가 들어가는데, Dialer, 웹 브라우저, 구글맵 어플리케이션 등에서는 위의 데이터처럼 실제 값을 받게 됩니다. 이와 같이 데이터에 실제 값을 넣는 경우는 Intents List : Invoking Google Applications on Android Devices 를 참고하세요.

이렇게 인텐트에 액션과 데이터를 설정한 후 인텐트를 실행시키면 다음과 같은 화면이 표시됩니다.



ACTION_CALL은 바로 왼쪽 화면처럼 바로 전화가 걸리게 되며, ACTION_DIAL은 오른쪽 화면에서 보는 것처럼, Dialer 액티비티가 호출된 후, 전화번호 입력 창에 우리가 데이터로 넘겨준 전화번호가 입력되어있는 것을 볼 수 있습니다.

다음으로는 오디오 데이터를 불러오는 인텐트를 보도록 하겠습니다.

데이터를 받아와야 하기 때문에 액션은 ACTION_GET_CONTENT, 특정 형식의 오디오 데이터가 아닌 모든 형식의 오디오 데이터를 불러와야 하므로 mimeType을 audio/* 로 지정합니다.

01.getAudioButton.setOnClickListener(new OnClickListener(){
02.  
03.            public void onClick(View v) {
04.                Intent i = new Intent(Intent.ACTION_GET_CONTENT);
05.                i.setType("audio/*");
06.                startActivityForResult(i, 0);
07.            }
08.              
09.        });

이 인텐트를 실행시켜 보면, 다음과 같은 화면이 나타나게 됩니다.




현재 오디오 데이터를 받아올 수 있는 컴포넌트로 음악 트랙 선택(Music플레이어)와 Sound Recorder 2개가 있는 것을 알 수 있습니다. 암시적 인텐트는 이런 식으로 해당 작업을 할 수 있는 모든 컴포넌트들을 호출할 수 있습니다. 따라서 인텐트 해석 결과, 위와 같이 해당 데이터를 처리할 수 있는 컴포넌트가 여러 가지인 경우 사용자가 원하는 컴포넌트를 선택하여 액션을 "마무리" 해 줘야 합니다. 

그럼, 바로 아래의 인텐트를 실행시켜볼까요? 

01.getAudioButtonWithChooser.setOnClickListener(new OnClickListener(){
02.  
03.            public void onClick(View v) {
04.                Intent i = new Intent(Intent.ACTION_GET_CONTENT);
05.                i.setType("audio/*");
06.                startActivityForResult(Intent.createChooser(i, "Select Audio Source..."), 0);
07.                }
08.                      
09.            });

이 인텐트를 실행시키게 되면 다음과 같은 화면이 표시됩니다.



여기에서는 인텐트를 실행시킬 때 IntentChooser를 사용하여 인텐트를 처리할 수 있는 컴포넌트가 하나 이상이 되어 여러 컴포넌트 중 하나를 선택할 때 나오는 다이얼로그의 이름을 지정해 줄 수 있습니다. 위와 같이 모든 어플리케이션에서 사용될 수 있는 파일 형식 (이미지, 사진, 비디오 등..)을 가진 데이터를 받아오게 될 경우, 위와 같이 IntentChooser를 사용하여 미리 다이얼로그의 이름을 지정해주는 것이 더 좋겠죠? 

마지막으로, 주소록에서 전화번호를 받아오는 인텐트를 보도록 하겠습니다.

[SDK 1.6 이하]

01.getContactsButton.setOnClickListener(new OnClickListener(){
02.  
03.            public void onClick(View v) {
04.                Intent i = new Intent(Intent.ACTION_GET_CONTENT);
05.                i.setType("vnd.android.cursor.item/phone");
06.                startActivityForResult(i,0);
07.            }
08.              
09.        });

위의 인텐트를 실행하면 다음과 같은 화면이 표시되며, 주소록에서 이름을 선택하게 되면 LogCat 화면에 선택한 이름의 전화번호가 저장된 주소(URI)가 표시되게 됩니다.

전화번호부 액티비티가 호출된 화면


DDMS에 선택한 주소록 데이터의 주소가 표시됩니다.



인텐트의 액션은 ACTION_PICK, 데이터로는 content://contacts/phones를 설정하였습니다. 이 인텐트는 전화번호부의 데이터를 받아올 수 있는 인텐트입니다. 

ACTION_PICK은 ACTION_GET_CONTENT와 같이 데이터를 받아올 때 사용하는 액션입니다. 하지만, 두 액션은 부가적으로 필요로 하는 정보에 다소 차이가 있습니다. ACTION_PICK은 부가적으로 필요한 데이터로 데이터의 실제 주소(URI; Uniform Resource Identifier)를 사용하며, ACTION_GET_CONTENT는 데이터의 유형(mimeType)을 사용합니다.

따라서, 일반적으로 이미지, 영상 등 여러 어플리케이션에서 범용으로 사용되는 데이터를 불러올 대는 ACTION_GET_CONTENT 및 해당 데이터의 타입을 가지는 인텐트를 사용하고 전화번호부처럼 특정 어플리케이션에서만 사용하는 데이터를 불러올 경우 ACTON_PICK 및 해당 데이터의 주소를 사용합니다. 하지만, 꼭 이렇게 정해진 것은 아니므로 편의에 따라 ACTION_GET_CONTENT 및 ACTION_PICK 중 하나를 선택하여 사용할 수도 있습니다. 

위의 전화번호부를 받아오는 인텐트는 아래와 같이 ACTION_GET_CONTENT를 사용하도록 만들 수도 있습니다.

1.Intent i = new Intent(Intent.ACTION_GET_CONTENT);
2.                i.setType("vnd.android.cursor.item/phones");
3.                startActivityForResult(i,0);

위의 인텐트를 실행하면 위의 인텐트와 같이 주소록이 표시되게 되며, 이름을 선택하게 되면 위의 ACTON_PICK을 사용한 인텐트와 동일하게 전화번호가 저장되어 있는 주소를 반환합니다.

SDK 2.0 (Eclair) 버전부터는 주소록의 주소가 다소 변경되었습니다. 따라서 위의 코드를 그대로 쓰시면 주소록을 정상적으로 받아올 수 없습니다. 2.0 에서는 다음과 같이 사용하시면 됩니다. 기존의 코드를 그대로 사용하시면 아래와 같이 주소록을 찾을 수 없다는 메시지가 표시됩니다.

 
Intent i = new Intent(Intent.ACTION_GET_CONTENT); // ACTION_GET_CONTENT 액션을 사용하는 경우
i.setType("vnd.android.cursor.item/phone_v2");
startActivityForResult(i,0);
Intent i = new Intent(Intent.ACTION_PICK); // ACTION_PICK 액션을 사용하는 경우
startActivityForResult(i,0);

위의 코드를 사용한 경우

1.6 버전용 코드를 사용한 경우




지금까지, 인텐트의 개념부터 시작하여 특징, 종류 및 실제로 암시적 인텐트를 사용하는 방법까지 알아보았습니다. 여기까지 잘 따라오셨다면 인텐트의 정체(!)에 대해 어느 정도 눈을 뜨셨을겁니다. :)

여기에서 인텐트에 대해 다루는 범위는 여기까지이지만, 이것 외에도 인텐트는 심오한 면들을 많이 가지고 있습니다. 안드로이드 시스템에서 없어서는 안될 핵심적인 역할을 하기도 하구요. 비록 영문이기는 하지만, 인텐트와 관련된 다른 내용들은 Android Developers 사이트의 문서들을 찾아보면 상세히 기술되어 있으니 이 문서들을 정독해보는 것을 추천합니다.
2010. 1. 15. 10:50

About Android





안드로이드의 역사

출처 : http://ko.wikipedia.org/wiki/구글_안드로이드

-        20057, 구글이 안드로이드 사를 인수

-        200711, 다국적 모바일 제조사가 모여 오픈 핸드셋 얼라이언스(OHA) 컨소시엄 결성

-        200810, 안드로이드 오픈소스 선언, Apache 2.0 GNU 라이센스로 공개

-        2009년 하반기, 모토로라의 드로이드 발표 이후 아이폰와의 대결구도 형성

 



모바일 플랫폼 비교

출처 : http://blog.daum.net/effortless/7864583

 

1. 우리팀이 모바일 개발을 할 때, 아이폰으로 갈까?

구분

설명

장점

단일 사용자 인터페이스 - 해상도/UI가 거의 동일하다. 해상도가 달라서 생기는 UI개발상의 어려움이 거의 없다.

단일 H/W 서포트 - 하드웨어 제작사가 Apple 한 회사여서, 하드웨어 때문에 말썽 피우는 일이 없다.

개발 툴킷 통합성 - XCode/Objective-C/Apple/iTunes로 대변되는 툴킷 및 환경은 매우 훌륭하다.

마켓의 성숙성 - 활발하고 거래가 잦은 앱스토어가 있다. 대박의 가능성이 있다.

단점

개발자 진입 장벽 -  국내의 대부분의 개발자들은 Apple  XCode상의 개발을 해 본적이 없다. 완전히 새로 배워야 한다. 일단 개발하려면 비싼 맥북부터 구입해야 한다.

애플사의 정책 -  애플사는 앱스토어에 올릴 때, 엄격한 검사를 하는데, 애플의 검사를 통과하지 못하면 앱스토어에 올리지 못한다. 이것에 대해서 불평이 상당하다. 앱스토어에 올리는 비용도 제법(?) 든다.

치열한 경쟁 - 이미 레드오션이나 다름없다. 개인들이 취미로 개발할 것이 아니고, 팀 단위 이상의 수익성을 바란다면, 상당한 개발력을 투입하여야 (적어도3~4M/M) 하며, 그게 수익을 가져다 줄지는 아무도 보장해 주지 못한다. 이미 완성도가 높은 애플릿들로 넘친다.

국내시장의 낮은 점유율 - 국내에서는 잘나가도 50만대, 무지 크게 잡아도 100만대 수준에서 멈출 것이다. 전체 시장의 5% 미만이라는 뜻이다. 기업이 기대할 수준의 수익을 가져다 주기에는 너무 작은 시장이다. 개인이 취미로 하자면, 큰 문제가 없을 것이다.

대응방안

개발할 대상에 따라 다른 것 같다. - 낮은 국시장 점유율에서라도 수익을 낼 수 있을 것 같으면, 아이폰이 적당하다. 국내용이 아니고, 세계 시장에 팔 수 있는 것이라면, 아이폰은 환상적인 플랫폼이다.

좀 럭셔리하고(?), 여유있는(?) 개인 개발자라면, 아이폰 만큼 좋은 취미생활이 따로 없다. 단 돈은 바라지 않는 게 좋다. 아마 개발하면서 먹은 햄버거와 콜라 값 정도나 간신히 나올 것이다. 어쩌다 운 좋아서 2~30만원을 넘겨도 그걸로 끝이다. 세계에 팔 수 있는 능력이 있는지 한번 테스트해 보기 바란다. 아마 그럴 수 있다면, 굳이 아이폰에서 개발 않고, 자기 블로그만 으로도 비슷한 수익을 만들 수 있을 것이다.

솔루션 개발사라면, 5%도 안되는 아이폰 고객들의 등쌀에 못 이겨, 어떤 식으로든 자사 솔루션에 대한 아이폰 인터페이스를 만들어 내야 할 것이다. 안그러면 솔루션 자체가 안 팔릴 테니까 이때는 수익보다는 개발비용 감소에 초점을 맞춰야 하는데, 최소한으로 아이폰 인터페이스를 만들라치면, 모바일 웹(아이폰 크기에 맞는 웹인터페이스)를 고려해 볼 수 있다. 그것은 폰특화된 것이 아니니까, 기존의 웹개발자가 대응할 수 있다.

 

2. 우리팀이 모바일 개발을 할 때, 안드로이드폰으로 갈까?

구분

설명

장점

낮은 진입 장벽  가장 많은 개발인구인 자바 개발자들이 타겟이다. 이클립스에 포함되는 개발 툴킷을 가지면 쉽게 개발에 뛰어들 수 있다.

구글 후광  구글 후광으로 추종자들이 제법 많다. 폰 개발사라면, 너도나도 안드로이드 폰 한종 정도는 만들 것이고, 국내에서는 SKTelecom이 안드로이드를 밀고갈 것 같다. 전략적으로 안드로이드를 미는 데 편승할 수 있으면 좋을 것이다.

쉬운 마켓 접근성  안드로이드 마켓은 등록이 매우 자유롭다. 진입 장벽이 더욱 낮다.

낮은 경쟁  현재의 안드로이드 마켓의 앱들은 매우 품질이 낮고 조잡하다. 품질에 좀 손을 쓰면 돋보일 가능성이 높다.

단점

더 낮은 국내 시장점유율  아마도 아이폰의 5%보다 더 낮은 국내시장 점유율을 보일 것이다. 국내용 앱으로는 수익성 맞추는 것이 불가능하겠다.

좀더 다양한 폰 환경 -  애플의 단일한 개발환경에 비해서, 폰들이 더 다양하다. 해상도, 터치 방식 등에서 상당히 다양한 환경이므로, 사용자 Experience를 구현하는데 좀더 어려울 것이다.

낮은 폰 성숙도  안드로이드 2.0이 최근에야 나왔고, 그게 기본으로 탑재되어 있는 폰은 거의 없다.내년 3분기 이후에야 주변에서 겨우 안드로이드 2.0폰 구경해 볼 수 있을 것이다.

구글의 우울한 판매정책  구글은 애플과 달리 적극적으로 앱을 판매하려고 하지 않는다. 안드로이드 시장에서 구글은 직접적인 수익이 제로이므로 당연하다. 유명한 게임 개발사는, 안드로이드 마켓이 전혀 판매유도를 하지 않는다는 이유로 (수익성이 낮으므로), 애플에만 집중하겠다고 선언하기까지 했다.

대응방안

개발자 훈련에 좋은 플랫폼이다. 모바일 개발 경험이 없는 개발자들을 모바일로 이행시키는 제일 좋은 방법이다.

오픈/자유 소프트웨어 추종자라면, 안드로이드 폰을 취미로 해 보는 것도 나쁘지 않다. 하지만, 애써서 만든 앱을, 주변 사람들에게 나눠줘서 폼내지는 못할 것이다. 당최 안드로이드 폰을 가진 사람이 있어야 말이지 그래도 실망 말라, 온라인에 테키들이 제법 있으니

팀수준이라면, 만약 구글추종 사업자(SKT, HTC, 삼성전자)등과 어떤 제휴관계를 형성해서 기업형 비즈모델을 만들었다면, 이 폰에 집중해도 상관없겠다. 그런 수준의 보장이 없이는 아마도 안드로이드 폰으로 수익만들기 힘들 것이다.

솔루션 개발사라면, 5%미만의 안드로이드 폰 고객들은 대부분 얼리어댑터형 테키일 가능성 크므로,싸악 무시해도 되지 않을까 싶다.

구글 추종 사업자들과 관계를 만들 정도의 역량이 있는 회사라면, 안드로이드 폰에 사업적으로 접근하는 것도 가능하겠다.

전세계(주로 유럽)에 판매 가능한 앱을 만들 수 있다면, 안드로이드를 주 타겟으로 삼아도 되겠다.

 

  이외에도 최근 Ms에서 윈도우 모바일 6.5를 발표한 이후 이를 바탕으로 하는 일명 윈도폰이 쏟아져 나오고 있는 상황이지만, 미비한 몸부림일 뿐이다. 국내에서 굴지의 핸드폰 생산업체라 할 수 있는 삼성전자에서 Bada’라고 하는 독자적인 모바일 운영체제와 개발툴킷을 선보였지만, 이에 대한 반응은 아직 지켜보자는 정도의 수준이다.

 

안드로이드 SDK 구성

1.      안드로이 API
SDK의 핵심은 개발자에게 안드로이드 스택에 대한 접근을 제공하는 안드로이드 API 라이브러리다. 이는 구글이 네이티브 안드로이드 애플리케이션을 만들기 위해 사용한 것과 동일한 라이브러리다. , 안드로이드 애플리케이션 개발자는 네이티브 애플리케이션(기본적인 기능 : 다이얼, 알람, 메시지 송신 등)에 대한 직접적인 조작 및 구현이 가능하다는 이야기이다.

2.      개발도구
안드로이드 소스 코드를 실행 가능한 안드로이드 애플리케이션으로 바꾸기 위해, SDK는 애플리케이션을 컴파일하고 디버그하도록 해주는 몇 가지 개념도구를 포함하고 있다.

3.      안드로이드 에뮬레이터
안드로이드 에뮬레이터는 변경 가능한 여러 스킨을 가지고 있는 완전히 인터랙티브한 안드로이드 장치에서 어떻게 보여지고 또 동작하게 되는지를 살펴볼 수 있다. 모든 안드로이드 애플리케이션은 Dalvik 가상머신에서 실행된다. 이 에뮬레이터는 하드웨어 중립적이기 떄문에, 그 어떤 단일한 하드웨어 구현보다도 더 나은 독립적인 테스트 환경을 제공한다. 특정 하드웨어를 목표로 할 경우에는 그 하드웨어에 포팅(Porting)을 통해 테스트 해보아야 한다.

4.      풍부한 문서
http://developer.android.com/reference/packages.html
SDK는 각 패키지와 클래스에 무엇이 포함되어 있는지 그리고 이들의 사용법은 어떻게 되는지를 자세히 정확하게 설명하고 있는 광범위한 코드 수준의 레퍼런스 정보를 가지고 있다.

5.      샘플코드
참조 : http://developer.android.com/guide/index.html → Best Practices
안드로이드 SDK는 각 API 기능의 사용법을 알려주는 엄선된 샘플 애플리케이션을 포함하고 있다.

6.   온라인 지원

http://groups.google.com/android-developers

구글 그룹을 통해서 다양한 정보를 얻을 수 있다.

 

 

 

 

 

 

안드로이드 소프트웨어 스택의 이해

 

1.      리눅스 커널
하드웨어 드라이버, 프로세스와 메모리 관련, 보안, 네트워크, 전력관리 등의 핵심 서비스는 리눅스 2.6 커널이 담당한다. 또한 커널은 하드웨어와 스택의 나머지 부분 사이에 추상 계층을 제공한다.

2.      라이브러리
라이브러리는 커널 바로 위에서 동작한다. 안드로이드는 libcSSL 같은 다양한 C/C++ 코어 라이브러리뿐만 아니라 다음과 같은 겉들을 포함하고 있다.
 

1.      안드로이드 런타임
안드로이드 폰을 리눅스 구현이 아닌 안드로이드 폰이게끔 만드는 것은 다름아닌 안드로이드 런타임이다. 코어 라이브러리와 Dalvik 가상머신을 포함하고 있는 안드로이드 런타임은 라이브러리와 함께 애플리케이션을 움직이게 하는 엔진으로서, 애플리케이션 프레임워크의 기본을 형성한다.

2.      코어 라이브러리
안드로이드의 개발은 자바로 이루어지지만 Dalvik은 자바 VM 이 아니다. 코어 안드로이드 라이브러리는 코어 자바 라이브러리에서 사용 가능한 대부분의 기능뿐만 아니라 안드로이드 전용 라이브러리도 제공한다.

3.      Dalvik 가상머신
Dalvik은 장치가 복수의 인스턴스를 효율적을 실행(멀티태스킹, 아직까지 아이폰은 싱글태스킹)할 수 있도록 보장하기 위한 최적화된 레지스터 기반의 가상머신이다. Dalvik은 스레딩과 하위 수준의 메모리 관리를 위해 리눅스 커널에 의존한다.

3.   애플리케이션 프레임워크

애플리케이션 프레임워크는 안드로이드 애플리케이션을 만드는 데 사용되는 클래스를 제공하며, 하드웨어 접근 및 사용자 인터페이스와 애플리케이션 리소스 관리를 위한 일반적 추상을 제공한다.

4.   애플리케이션 계층

네이티브 애플리케이션과 서드파티 애플리케이션은 모두 동일한 API 라이브러리를 사용하는 애플리케이션 계층위에 구축된다. 애플리케이션 계층은 애플리케이션 프레임워크를 통해 사용가능한 클래스와 서비스를 사용함으로써 안드로이드 런타임 내에서 실행된다.

 

Dalvik 가상머신

안드로이드의 핵심 구성요소 가운데 하나가 바로 Dalvik 가상머신이다. 안드로이드는 자바 ME 같은 전통적인 자바 가상 머신을 사용하지 않고, 단일 장치상에서 복수의 인스턴스가 효율적으로 실행되게끔 보장하도록 설계된 자신만의 고유한 커스텀 VM 을 사용한다.

Dalvik VM 은 장치 하부에 놓인 리눅스 커널을 사용해 보안, 스레딩, 그리고 프로세스와 메모리 관리 등의 하위 수준 기능을 처리한다. 하부에 있는 리눅스 OS 상에서 직접 실행되는 C/C++ 애플리케이션을 작성하는 것도 가능하지만 그럴 필요는 없음.

안드로이드 애플리케이션 아키텍쳐

안드로이드 아키텍처는 컴포넌트 재사용 개념을 장려하며, 액티비티와 서비스 그리고 데이터를 발행해, 설정한 보안 제한에 의해 관리되는 접근을 통해 다른 애플리케이션과 공유할 수 있도록 해준다.

1.    액티비티 관리자
액티비티 스택 관리를 포함하여 액티비티의 수명 주기를 제어한다.

2.   
액티비티의 사용자 인터페이스를 구성하는 데 사용된다.

3.    알림 관리자
사용자에게 신호를 보내기 위해 일관되면서도 간섭적이지 않은 메커니즘을 제공한다.

4.    콘텐츠 공급자
애플리케이션이 다른 애플리케이션과 데이터를 공유할 수 있도록 해준다.

5.    리소스 관리자
문자열과 그래픽스 같은 외부화되는 비코드 리소스를 지원한다.

 

 

 

안드로이드 개발환경 구축하기

1.    이클립스 다운로드
Galileo              : http://www.eclipse.org/downloads/
Ganymade              : http://www.eclipse.org/ganymede/

2.   안드로이드 SDK 다운로드
http://developer.android.com/sdk/index.html

3.   이클립스 ADT 다운로드
eclipse – installing ADT
http://dl-ssl.google.com/android/eclipse

4.      AVM 생성하기
{Android-SDK}/tools/ 에서 생성하는 방법
android create avd --target 2 --name my_avd

              Eclipse – Android SDK and AVD Manager 에서 생성하기

5.   Hello, Android 띄우기

              이클립스 내에서 새로운 Android 프로젝트 생성 후 실행하면 뜸.

 

 

 

 

 

안드로이드 애플리케이션의 종류

1.    포그라운드 액티비티(Foreground Activity)
활성화 되어 화면에 있을 때만 쓸모 있는 애플리케이션으로서, 화면에 보이지 않을 때는 사실상 중단된다. 게임과 맵 매시업이 이 부류에 속하는 대표적인 예다.

2.    백그라운드 액티비티(Background Activity)
구성이 변경되고 있는 경우를 제외한 대부분의 시간을 화면에 보이지 않은 채로 실행되는 상호작용이 제한된 애플리케이션, 전화 차단 애플리케이션이나 SMS 자동응답기가 이 부류에 속한다.

3.    인터미턴트 액티비티(Intermittent Activity)
드문드문 상호작용이 있긴 하지만 대부분의 작업을 백그라운드에서 수행한다. 이런 류의 애플리케이션을 실행하면 보통 소리소문 없이 동작하다가 적절한 때에 사용자에게 통지한다. 미디어 플레이어가 대표적인 예다.

 

하드웨어 설계시 고려사항

-        느린 처리 속도 : 효율적일 것

-        제한된 RAM : 제한된 저장 공간을 예측할 것

-       제한된 영구 저장공간 : “”

-        저해상도의 작은 화면 : 작은 화면을 위해 디자인할 것
참조 : http://uxfactory.com/787

-       비싼 데이터 전송 비용 : 국내의 모바일 웹 데이터 요금은 무척 비싸다.

-        다소 신뢰성이 떨어지는 데이터 연결 : 느린 속도와 긴 지연 시간을 예측할 것

-       제한된 배터리 수명 : 데이터 송수신, 사용시간에 따라서 배터리 수명이 달라진다.

 

사용자 환경 고려하기

-       상황에 따라 효율적으로 동작해야 한다.

-       백그라운드에서 포그라운드로 매끄럽게 전환되어야 한다.

-       품위 있어야 한다.

-       일관된 사용자 인터페이스를 보여줘야 한다.

-       반응성이 좋아야 한다.

 

빠르고 효율적일 것

반응성이 좋을 것

안전한 애플리케이션 개발하기

2010. 1. 15. 10:39

Android Run-Time 분석





안드로이드는 구글의 모바일 운영체제로 알려져 있다. 실제 안드로이드는 Linux Kernel 위에 돌아가는 RunTime과 그에 따른 라이브러리라고 보아야 한다. 물론 모바일 플랫폼에 맞게 리눅스 커널이 패치되기는 하지만 운영체제의 기본적은 core는 Linux라고 봐야 할 것이다.
위 그림중 초록색 부분이 C/C++ 구성 부분이고 파란색 부분이 Java로 구성된 부분이다. Android Runtime은 Dalvik 이라는 VM과 Core libraries로 구성되어 있다. Linux Kernel은 ashmem(android shared memory)이라고 불리는 Shared Memeroy 부분하고 Binder Driver 부분이 모바일 플랫폼에 맞게 만들어져 있다. Binder는 프로세스간 통신하는 Overhead를 줄이기 위해서 만들어져 있고 Power Management는 기존의 리눅스에서 사용되는 모듈을 사용하지 않고 모바일 환경에 맞도록 개발된 모듈을 가지고 있다.
Android 라이브러리는 GNU 기반의 소스를 사용하지 않는다. 이는 상용화에 제약이 없도록 GPL 로 부터 해방되기 위함이다. 이에 libC도 glibc를 사용하지 않고 있다.
Android의 개발은 Eclipse의 ADT Plug-in을 통해서 Java로 컴파일 되고 class와 resource가 Dx 컨버터를 통해서 Android App(.apk)로 만들어지며 이 apk가 Dalvik VM위에서 동작하게 된다.
안드로이드 개발 환경은 eclipse와 제공되는 emulator를 가지고 가능하며 emulator는 실제 Chip위에 올라가는 것 같이 만들어져 있다. 안드로이드는 어플리케이션을 빠르게 구동하기 위해서 zygote라는 미리 구동되어 있는 프로세스를 가지고 있으며 이 프로세스는 특정 어플리케이션과 Binding되어 동작하기 전의 상태로 즉 중립적인 상태를 유지한다.
Dalvik Virtual Machine은 Register기반의 가상 머신으로 모바일 환경에 맞게 구성된 VM이고 더 효율적인 인터피리터이다.
워낙 내용이 많아서 추상적으로 요약을 했다. 자세한 부분은 http://www.kandroid.org 를 보아도 될듯.
2010. 1. 14. 17:34

Android Initialization Process





init is the first process after kernel started. The corresponding source code lies in: device/system/init. It does the following tasks step by step:

1.       Initialize log system.

2.       Parse /init.rc and /init.%hardware%.rc.

3.       Execute early-init action in the two files parsed in step 2.

4.       Device specific initialize. For example, make all device node in /dev and download firmwares.

5.       Initialize property system. Actually the property system is working as a share memory. Logically it looks like a registry under Windows system.

6.       Execute init action in the two files parsed in step 2.

7.       Start property service.

8.       Execute early-boot and boot actions in the two files parsed in step 2.

9.       Execute property action in the two files parsed in step 2.

10.   Enter into an indefinite loop to wait for device/property set/child process exit events. For example, if an SD card is plugined, init will receive a device add event, so it can make node for the device. Most of the important process is forked in init, so if any of them crashed, init will receive a SIGCHLD then translate it into a child process exit event, so in the loop init can handle the process exit event and execute the commands defined in *.rc(it will run command onrestart).

The .rc file is a script file defined by Android. The default is device/system/rootdir/init.rc. We can take a loot at the file format(device/system/init/readme.txt is a good overall introduction of the script). Basically the script file contains actions and services.

Actions

-------

Actions are named sequences of commands. Actions have a trigger which is used to determine when the action should occur.  When an event occurs which matches an action's trigger, that action is added to the tail of a to-be-executed queue (unless it is already on the queue).

Each action in the queue is dequeued in sequence and each command in that action is executed in sequence.  Init handles other activities (device creation/destruction, property setting, process restarting) "between" the execution of the commands in activities.

Actions take the form of:

on <trigger>

   <command>

   <command>

   <command>

...

Services

--------

Services are programs which init launches and (optionally) restarts when they exit.  Services take the form of:

service <name> <pathname> [ <argument> ]*

   <option>

   <option>

   ...

Options

-------

Options are modifiers to services.  They affect how and when init runs the service.

Triggers

--------

Triggers are strings which can be used to match certain kinds of events and used to cause an action to occur.

The builtin supported commands are defined in device/system/init/keywords.h. Commands are implementd in device/system/init/bultins.c.

The init program only executes five kinds of triggers: “early-init”, “init”, “early-boot”, “boot”, “property:*”. Take a look at the following line in default init.rc.

class_start default

This line is a command for the action corresponding to “boot” trigger. It will start all services whose class name equals to “default”. By default, if no class option is defined for a service, the service’s class name is “default”. So this line will start all the services in the order of position in the file by default. (BTW, you can start any service using start commands, if you like.) Any service is run as a forked process of init, take a look at the source code of service_start in device/system/init.c.

So according to the default init.rc, the following services will be executed step by step:

console: star a shell. The source is in device/system/bin/ash.

adbd: start adb daemon. The source is in device/tools/adbd. By default is disabled.

servicemanager: start binder system. The source is in device/commands/binder.

mountd: mount all fs defined in /system/etc/mountd.conf if started, receive commands through local socket to mount any fs. The source is in device/system/bin/mountd.

debuggerd: start debug system. The source is in device/system/bin/debuggerd.

rild: start radio interface layer daemon. The source is in device/commands/rind.

zygote: start Android Java Runtime and start system server. It’s the most important service. The source is in device/servers/app.

media: start AudioFlinger, MediaPlayerService and CameraService. The source is in device/commands/mediaserver.

bootsound: play the default boot sound /system/media/audio/ui/boot.mp3. The source is in device/commands/playmp3.

dbus: start dbus daemon, it’s only used by BlueZ. The source is in device/system/Bluetooth/dbus-daemon.

hcid: redirect hcid’s stdout and stderr to the Android logging system. The source is in device/system/bin/logwrapper. By default is disabled.

hfag: start Bluetooth handsfree audio gateway, it’s only used by BlueZ. The source is in device/system/Bluetooth/bluez-utils. By default is disabled.

hsag: start Bluetooth headset audio gateway, it’s only used by BlueZ. The source is in device/system/Bluetooth/bluez-utils. By default is disabled.

installd: start install package daemon. The source is in device/servers/installd.

flash_recovery: load /system/recovery.img. The source is in device/commands/recovery/mtdutils.

Zygote service does the following tasks step by step:

1.       Create JAVA VM.

2.       Register android native function for JAVA VM.

3.       Call the main function in the JAVA class named com.android.internal.os.ZygoteInit whose source is device/java/android/com/android/internal/os/ZygoteInit.java.

a)         Load ZygoteInit class

b)        Register zygote socket

c)        Load preload classes(the default file is device/java/android/preloaded-classes)

d)        Load preload resources

e)         Call Zygote::forkSystemServer (implemented in device/dalvik/vm/InternalNative.c) to fork a new process. In the new process, call the main function in the JAVA class named com.android.server.SystemServer, whose source is in device/java/services/com/android/server.

                         i.              Load libandroid_servers.so

                       ii.              Call JNI native init1 function implemented in device/libs/android_servers/com_android_server_SystemServers. It only calls system_init implemented in device/servers/system/library/system_init.cpp.

l         If running on simulator, instantiate AudioFlinger, MediaPlayerService and CameraService here.

l         Call init2 function in JAVA class named com.android.server.SystemServer, whose source is in device/java/services/com/android/server. This function is very critical for Android because it start all of Android JAVA services.

l         If not running on simulator, call IPCThreadState::self()->joinThreadPool() to enter into service dispatcher.

SystemServer::init2 will start a new thread to start all JAVA services as follows:

Core Services:

1.       Starting Power Manager

2.       Creating Activity Manager

3.       Starting Telephony Registry

4.       Starting Package Manager

5.       Set Activity Manager Service as System Process

6.       Starting Context Manager

7.       Starting System Context Providers

8.       Starting Battery Service

9.       Starting Alarm Manager

10.   Starting Sensor Service

11.   Starting Window Manager

12.   Starting Bluetooth Service

13.   Starting Mount Service

Other services

1.       Starting Status Bar Service

2.       Starting Hardware Service

3.       Starting NetStat Service

4.       Starting Connectivity Service

5.       Starting Notification Manager

6.       Starting DeviceStorageMonitor Service

7.       Starting Location Manager

8.       Starting Search Service

9.       Starting Clipboard Service

10.   Starting Checkin Service

11.   Starting Wallpaper Service

12.   Starting Audio Service

13.   Starting HeadsetObserver

14.   Starting AdbSettingsObserver

Finally SystemServer::init2 will call ActivityManagerService.systemReady to launch the first activity by senting Intent.CATEGORY_HOME intent.

There is another way to start system server, which is through a program named system_server whose source is device/servers/system/system_main.cpp. It also calls system_init to start system services. So there is a question: why does Android have two methods to start system services? My guess is that directly start system_server may have synchronous problem with zygote because system_server will call JNI to start SystemServer::init2, while at that time zygote may not start JAVA VM yet. So Android uses another method. After zynote is initialized, fork a new process to start system services.

2010. 1. 14. 10:24

iPhone OS Architecture




iPhone OS의 기술 레이어는 다음과 같이 구현되어 있습니다.

그림. Layers of iPhone OS

각 레이어에서 하는 일은 다음과 같습니다.

1. Cocoa Touch Layer
  • 가장 상위 레이어로서 어플리케이션 개발에 필요한 프레임워크를 제공
  • Apple Push Notification Service: 사용자에게 정보를 통지하는 방법을 제공
  • Address Book UI Framework:  주소록 UI를 제공
  • Message UI Framework: 이메일을 구성하고 보낼 수 있음
  • Map Kit Framework: 지도 인터페이스를 제공, 지도에 주석을 달 수도 있음
  • Peer to Peer Support: P2P 네트워크 프레임워크
  • UIKit Framework: 그래픽, event-driven 어플리케이션 구현에 관련된 기능을 제공
 
2. Media Layer
  • 그래픽, 오디오, 비디오관련 기능을 제공하는 레이어
  • 그래픽 기술: Quartz 2D, Quartz Animation, OpenGL ES framework
  • 오디오 기술: AV Foundation, Core Autio, OpenAL
  • 비디오 기술: Media Player framework

3. Core Services Layer
  • Address Book Framework: 주소록 자료에 접근한 수 있게 함.
  • Core Data Framework: 툴을 이용한 데이터 모델을 구현할 수 있음
  • Core Foundation Framework: 어플리케이션을 위한 기본적인 데이터 관리와 서비스를 제공
  • Core Location Framework: GPS, cell, WiFi등을 이용하여 삼각측정으로 장치의 현재 위치를 파악할 수 있음
  • Foundation Framework: Core Foundation Framwork의 wrapper framework
  • Store Kit framework: 어플리케이션에서 콘텐츠와 서비스의 구매 환경을 제공
  • SQLite: lightweight SQL database
  • XML Support: NSXMLParser를 이용하여 XML문서를 탐색할 수 있음

4. Core OS Layer
  • CFNetwork framework: 네트워크 프로토콜의 객체지향적 인터페이스
  • External Accessory framework: 외부 장치와 통신할 수 있게 지원
  • Security framework: 어플리케이션의 데이터 보안을 지원
  • System: kernel과 관련된 기능 제공



5. Reference

  1.  "iPhone OS Technologies", iPhone Dev Center


http://leesort.tistory.com/50