스마트폰 OS인 Android에서 Intent 관련 사항을 정리 한다.


Intent 개요


  • Intent 정의
    원하는 실제 행동을 호출할 때 사용하는 객체 애플리케이션에서 다른 모듈의 기능을 호출할 때 사용하는 객체 Intent 핸들러(Activity, Service, BroadcastReceiver)에 의해서 처리됨
 public class android.content.Intent implements Parcelable

![Android Intent|700px](img/Android intent.png)

  • 구성
    Component가 Data와 Type로 지정된 대상에 대해 Category와 Action으로 지정된 행위를 한다. 추가적인 정보는 Extras로 제공 한다. {|cellspacing="0" cellpadding="2" border="1" width="100%" bgcolor="#FFFFFF" align="center" |- |width="20%" align="center" style="background-color:#eee;"|Category |width="80%"|
  • 인텐트의 분류로 여러 값을 가질 수 있음
  • Category가 있고 Action이 없을 경우 모든 Action이 매핑됨
 CATEGORY_DEFAULT = "android.intent.category.DEFAULT";
 CATEGORY_BROWSABLE = "android.intent.category.BROWSABLE";
 CATEGORY_ALTERNATIVE = "android.intent.category.ALTERNATIVE";
 CATEGORY_SELECTED_ALTERNATIVE = "android.intent.category.SELECTED_ALTERNATIVE";
 CATEGORY_TAB = "android.intent.category.TAB";
 CATEGORY_LAUNCHER = "android.intent.category.LAUNCHER";
 CATEGORY_INFO = "android.intent.category.INFO";
 CATEGORY_HOME = "android.intent.category.HOME";
 CATEGORY_PREFERENCE = "android.intent.category.PREFERENCE";
 CATEGORY_DEVELOPMENT_PREFERENCE = "android.intent.category.DEVELOPMENT_PREFERENCE";
 CATEGORY_EMBED = "android.intent.category.EMBED";
 CATEGORY_MONKEY = "android.intent.category.MONKEY";
 CATEGORY_TEST = "android.intent.category.TEST";
 CATEGORY_UNIT_TEST = "android.intent.category.UNIT_TEST";
 CATEGORY_SAMPLE_CODE = "android.intent.category.SAMPLE_CODE";
 CATEGORY_OPENABLE = "android.intent.category.OPENABLE";
 CATEGORY_FRAMEWORK_INSTRUMENTATION_TEST = "android.intent.category.FRAMEWORK_INSTRUMENTATION_TEST";
 CATEGORY_CAR_DOCK = "android.intent.category.CAR_DOCK";
 CATEGORY_DESK_DOCK = "android.intent.category.DESK_DOCK";

|- |align="center" style="background-color:#eee;"|Action |

  • 인텐트의 액션
  • Category가 없고 Action이 있을 경우, Category가 없는 Action만 매핑됨
 ACTION_MAIN = "android.intent.action.MAIN";
 ACTION_VIEW = "android.intent.action.VIEW";
 ACTION_DEFAULT = "android.intent.action.VIEW";
 ACTION_ATTACH_DATA = "android.intent.action.ATTACH_DATA";
 ACTION_EDIT = "android.intent.action.EDIT";
 ACTION_INSERT_OR_EDIT = "android.intent.action.INSERT_OR_EDIT";
 ACTION_PICK = "android.intent.action.PICK";
 ACTION_CREATE_SHORTCUT = "android.intent.action.CREATE_SHORTCUT";
 ACTION_CHOOSER = "android.intent.action.CHOOSER";
 ACTION_GET_CONTENT = "android.intent.action.GET_CONTENT";
 ACTION_DIAL = "android.intent.action.DIAL";
 ACTION_CALL = "android.intent.action.CALL";
 ACTION_SENDTO = "android.intent.action.SENDTO";
 ACTION_SEND = "android.intent.action.SEND";
 ACTION_SEND_MULTIPLE = "android.intent.action.SEND_MULTIPLE";
 ACTION_ANSWER = "android.intent.action.ANSWER";
 ACTION_INSERT = "android.intent.action.INSERT";
 ACTION_DELETE = "android.intent.action.DELETE";
 ACTION_RUN = "android.intent.action.RUN";
 ACTION_SYNC = "android.intent.action.SYNC";
 ACTION_PICK_ACTIVITY = "android.intent.action.PICK_ACTIVITY";
 ACTION_SEARCH = "android.intent.action.SEARCH";
 ACTION_SYSTEM_TUTORIAL = "android.intent.action.SYSTEM_TUTORIAL";
 ACTION_WEB_SEARCH = "android.intent.action.WEB_SEARCH";
 ACTION_ALL_APPS = "android.intent.action.ALL_APPS";
 ACTION_SET_WALLPAPER = "android.intent.action.SET_WALLPAPER";
 ACTION_BUG_REPORT = "android.intent.action.BUG_REPORT";
 ACTION_FACTORY_TEST = "android.intent.action.FACTORY_TEST";
 ACTION_CALL_BUTTON = "android.intent.action.CALL_BUTTON";
 ACTION_VOICE_COMMAND = "android.intent.action.VOICE_COMMAND";
 ACTION_SEARCH_LONG_PRESS = "android.intent.action.SEARCH_LONG_PRESS";
 ACTION_POWER_USAGE_SUMMARY = "android.intent.action.POWER_USAGE_SUMMARY";
 ACTION_SCREEN_OFF = "android.intent.action.SCREEN_OFF";
 ACTION_SCREEN_ON = "android.intent.action.SCREEN_ON";
 ACTION_USER_PRESENT = "android.intent.action.USER_PRESENT";
 ACTION_TIME_TICK = "android.intent.action.TIME_TICK";
 ACTION_TIME_CHANGED = "android.intent.action.TIME_SET";
 ACTION_DATE_CHANGED = "android.intent.action.DATE_CHANGED";
 ACTION_TIMEZONE_CHANGED = "android.intent.action.TIMEZONE_CHANGED";
 ACTION_BOOT_COMPLETED = "android.intent.action.BOOT_COMPLETED";
 ACTION_CLOSE_SYSTEM_DIALOGS = "android.intent.action.CLOSE_SYSTEM_DIALOGS";
 ACTION_PACKAGE_INSTALL = "android.intent.action.PACKAGE_INSTALL";
 ACTION_PACKAGE_ADDED = "android.intent.action.PACKAGE_ADDED";
 ACTION_PACKAGE_REPLACED = "android.intent.action.PACKAGE_REPLACED";
 ACTION_PACKAGE_REMOVED = "android.intent.action.PACKAGE_REMOVED";
 ACTION_PACKAGE_CHANGED = "android.intent.action.PACKAGE_CHANGED";
 ACTION_PACKAGE_RESTARTED = "android.intent.action.PACKAGE_RESTARTED";
 ACTION_PACKAGE_DATA_CLEARED = "android.intent.action.PACKAGE_DATA_CLEARED";
 ACTION_UID_REMOVED = "android.intent.action.UID_REMOVED";
 ACTION_WALLPAPER_CHANGED = "android.intent.action.WALLPAPER_CHANGED";
 ACTION_CONFIGURATION_CHANGED = "android.intent.action.CONFIGURATION_CHANGED";
 ACTION_LOCALE_CHANGED = "android.intent.action.LOCALE_CHANGED";
 ACTION_BATTERY_CHANGED = "android.intent.action.BATTERY_CHANGED";
 ACTION_BATTERY_LOW = "android.intent.action.BATTERY_LOW";
 ACTION_BATTERY_OKAY = "android.intent.action.BATTERY_OKAY";
 ACTION_POWER_CONNECTED = "android.intent.action.ACTION_POWER_CONNECTED";
 ACTION_POWER_DISCONNECTED = "android.intent.action.ACTION_POWER_DISCONNECTED";
 ACTION_SHUTDOWN = "android.intent.action.ACTION_SHUTDOWN";
 ACTION_DEVICE_STORAGE_LOW = "android.intent.action.DEVICE_STORAGE_LOW";
 ACTION_DEVICE_STORAGE_OK = "android.intent.action.DEVICE_STORAGE_OK";
 ACTION_MANAGE_PACKAGE_STORAGE = "android.intent.action.MANAGE_PACKAGE_STORAGE";
 ACTION_UMS_CONNECTED = "android.intent.action.UMS_CONNECTED";
 ACTION_UMS_DISCONNECTED = "android.intent.action.UMS_DISCONNECTED";
 ACTION_MEDIA_REMOVED = "android.intent.action.MEDIA_REMOVED";
 ACTION_MEDIA_UNMOUNTED = "android.intent.action.MEDIA_UNMOUNTED";
 ACTION_MEDIA_CHECKING = "android.intent.action.MEDIA_CHECKING";
 ACTION_MEDIA_NOFS = "android.intent.action.MEDIA_NOFS";
 ACTION_MEDIA_MOUNTED = "android.intent.action.MEDIA_MOUNTED";
 ACTION_MEDIA_SHARED = "android.intent.action.MEDIA_SHARED";
 ACTION_MEDIA_BAD_REMOVAL = "android.intent.action.MEDIA_BAD_REMOVAL";
 ACTION_MEDIA_UNMOUNTABLE = "android.intent.action.MEDIA_UNMOUNTABLE";
 ACTION_MEDIA_EJECT = "android.intent.action.MEDIA_EJECT";
 ACTION_MEDIA_SCANNER_STARTED = "android.intent.action.MEDIA_SCANNER_STARTED";
 ACTION_MEDIA_SCANNER_FINISHED = "android.intent.action.MEDIA_SCANNER_FINISHED";
 ACTION_MEDIA_SCANNER_SCAN_FILE = "android.intent.action.MEDIA_SCANNER_SCAN_FILE";
 ACTION_MEDIA_BUTTON = "android.intent.action.MEDIA_BUTTON";
 ACTION_CAMERA_BUTTON = "android.intent.action.CAMERA_BUTTON";
 ACTION_GTALK_SERVICE_CONNECTED = "android.intent.action.GTALK_CONNECTED";
 ACTION_GTALK_SERVICE_DISCONNECTED = "android.intent.action.GTALK_DISCONNECTED";
 ACTION_INPUT_METHOD_CHANGED = "android.intent.action.INPUT_METHOD_CHANGED";
 ACTION_AIRPLANE_MODE_CHANGED = "android.intent.action.AIRPLANE_MODE";
 ACTION_PROVIDER_CHANGED = "android.intent.action.PROVIDER_CHANGED";
 ACTION_HEADSET_PLUG = "android.intent.action.HEADSET_PLUG";
 ACTION_NEW_OUTGOING_CALL = "android.intent.action.NEW_OUTGOING_CALL";
 ACTION_REBOOT = "android.intent.action.REBOOT";
 ACTION_DOCK_EVENT = "android.intent.action.DOCK_EVENT";

|- |align="center" style="background-color:#eee;"|Data |

  • 작업 요청 URI

  • 종류 1 : scheme, authority, path

    • 예) weather://com.msi.manning/loc?zip=12345
  • 종류 2 : MIME 형식, Content Provider와 연계됨

    • 예) '''content://'''com.google.provider.NotePad/notes
  • Scheme가 있고 Type이 없으면, 모든 Type이 매핑됨

  • Scheme가 없고 Type이 있으면, 모든 Scheme가 매핑됨

  • Scheme가 없고 Type이 없으면, 매핑되지 않음
    |- |align="center" style="background-color:#eee;"|Type |

  • MIME 타입
    |- |align="center" style="background-color:#eee;"|Component |

  • 실제 작업을 실행할 Class

 new ComponentName(Package_Name, Class_Name)

|- |align="center" style="background-color:#eee;"|Extras |

  • 추가 데이터, Bundle
 Intent result = new Intent();
 result.putExtra(LoginActivity.TEXT_RESULT, "finish");
 
 String result = data.getStringExtra(TEXT_RESULT);

|}

  • 인텐트 선언

    • 명시적 선언 : new Intent(Context packageContext, Class cls)
    • 묵시적 선언 : new Intent(String action, Uri uri)
  • 인텐트 핸들러
    {|cellspacing="0" cellpadding="2" border="1" width="100%" bgcolor="#FFFFFF" align="center" |- |width="20%" align="center" style="background-color:#eee;"|Activity |width="80%"|

  • android.content.Context.startActivity(Intent intent)

  • startActivityForResult(Intent, requestCode)
    |- |align="center" style="background-color:#eee;"|Service |

  • android.content.Context.startService(Intent intent)

  • android.content.Context.bindService(Intent intent, ServiceConnection serviceconnection, int i)
    |- |align="center" style="background-color:#eee;"|BroadcastReceiver |

  • android.content.Context.sendBroadcast(Intent intent)

  • android.content.Context.sendStickyBroadcast(Intent intent)

  • android.content.Context.sendOrderedBroadcast(Intent intent, String receiverPermission)

  • android.content.BroadcastReceiver.onReceive(Context context, Intent intent)
    |}

  • IntentFilter

    • AndroidManifest.xml
 Intent intent = new Intent(Constants.INTENT_ACTION_VIEW_LIST);
 startActivity(intent);
 
  또는  또는 
     ''''''
         
         
         
     ''''''
 

Intent 활용 사례



연락처 Intent

  • 연락처 조회
 //--- RAW_CONTACT_ID로 연락처 조회
 //--- 최신 스마트폰에서 정상 동작하지 않는 경우가 발생함
 intent = new Intent(Intent.ACTION_VIEW, Uri.parse("content://contacts/people/" + String.valueOf(contact.getId())));
 startActivity(intent);
 
 //--- CONTACT_ID로 연락처 조회
 intent = new Intent(Intent.ACTION_VIEW);
 intent.setData(Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_URI, contact.getContactId()));
 startActivity(intent);
  • 연락처 등록
 intent = new Intent(Intent.ACTION_INSERT, Uri.parse("content://contacts/people"));
 startActivity(intent);
  • 연락처 수정
 intent = new Intent(Intent.ACTION_EDIT, Uri.parse("content://contacts/people/" + String.valueOf(contact.getId())));
 startActivity(intent);
  • 연락처 삭제
 intent = new Intent(Intent.ACTION_DELETE, Uri.parse("content://contacts/people/" + String.valueOf(contact.getId())));
 startActivity(intent);

전화 Intent

  • 권한 설정 (AndroidManifest.xml)
 전화 걸기         : CALL_PHONE = "android.permission.CALL_PHONE"
 긴급 통화         : CALL_PRIVILEGED = "android.permission.CALL_PRIVILEGED"
 폰 상태 읽기      : READ_PHONE_STATE = "android.permission.READ_PHONE_STATE"
 폰 상태 수정      : MODIFY_PHONE_STATE = "android.permission.MODIFY_PHONE_STATE"
 브로드케스팅 수신 : PROCESS_OUTGOING_CALLS = "android.permission.PROCESS_OUTGOING_CALLS"
 전화 걸기 이전    : ACTION_NEW_OUTGOING_CALL = "android.intent.action.NEW_OUTGOING_CALL"
  • 전화걸기 화면
 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + TelNumber));
 startActivity(intent);
  • 전화걸기
 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + TelNumber));
 startActivity(intent);

SMS Intent

  • 권한 설정 (AndroidManifest.xml)
 수신 모니터링       : RECEIVE_SMS = "android.permission.RECEIVE_SMS"
 읽기 가능           : READ_SMS = "android.permission.READ_SMS" 
 발송 가능           : SEND_SMS = "android.permission.SEND_SMS"
 SMS Provider로 전송 : WRITE_SMS = "android.permission.WRITE_SMS"
                     : BROADCAST_SMS = "android.permission.BROADCAST_SMS"
  • SMS 발송 화면
 Intent intent = new Intent(Intent.ACTION_VIEW);
 intent.putExtra("sms_body", "The SMS text");
 intent.setType("vnd.android-dir/mms-sms");
 startActivity(intent);
  • SMS 보내기
 Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.parse("smsto:" + contact.getHandphone()));
 intent.putExtra("sms_body", "The SMS text");
 intent.setType("vnd.android-dir/mms-sms");
 startActivity(intent);

이메일 Intent

  • 이메일 발송 화면
 Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.parse("mailto:" + contact.getEmail()));
 startActivity(intent);

브라우저 Intent

  • Browser에서 URL 호출하기
 new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com/"));
 startActivity(intent);
  • 브라우저에서 검색
 Intent intent = new Intent(Intent.ACT ION_WEB_SEARCH);
 intent.putExtra(SearchManager.QUERY, "검색어");
 startActivity(intent);
  • Header 정보 전달
 Bundle extraHeaders = new Bundle();
 extraHeaders.putString("user_name", "test");
 extraHeaders.putString("user_pass", "test");
 intent.putExtra(Browser.EXTRA_HEADERS, extraHeaders);

지도 Intent

  • 지도 보기
 Uri uri = Uri.parse ("geo: 38.00, -35.03");
 Intent intent = new Intent(Intent.ACTION_VIEW, uri);
 startActivity(intent);

안드로이드 마켓 Intent

  • 안드로이드 마켓에서 Apps 검색
 Uri uri = Uri.parse("market://search?q=pname:전제_패키지_명");  
 //--- 예) market://search?q=pname:com.jopenbusiness.android.smartsearch
 Intent intent = new Intent(Intent.ACTION_VIEW, uri);  
 startActivity(intent);  
  • 안드로이드 마켓의 App 상세 화면
 Uri uri = Uri.parse("market://details?id=전제_패키지_명");
 //--- 예) market://details?id=com.jopenbusiness.android.smartsearch
 Intent intent = new Intent(Intent.ACTION_VIEW, uri);  
 startActivity(intent);

갤럭시S의 Intent

  • 패키지명과 클래스명으로 App 호출
 intent = new Intent(Intent.ACTION_MAIN);
 intent.setComponent(new ComponentName("패키지명", "전체_클래스명"));
 startActivity(intent);
  • 전화, SMS

    • 전화번호부 : com.android.contacts, com.sec.android.app.contacts.PhoneBookTopMenuActivity
    • 전화 : com.sec.android.app.dialertab, com.sec.android.app.dialertab.DialerTabActivity
    • 최근기록 : com.sec.android.app.dialertab, com.sec.android.app.dialertab.DialerTabDialerActivity
    • 메시지 : com.sec.mms, com.sec.mms.Mms
  • 이메일 : com.android.email, com.android.email.activity.Welcome

  • 일정 : com.android.calendar, com.android.calendar.LaunchActivity

  • 인터넷 : com.android.browser, com.android.browser.BrowserActivity

  • Google의 Android용 앱

    • 검색 : com.google.android.googlequicksearchbox, com.google.android.googlequicksearchbox.SearchActivity
    • 음성 검색 : com.google.android.voicesearch, com.google.android.voicesearch.RecognitionActivity
    • Gmail : com.google.android.gm, com.google.android.gm.ConversationListActivityGmail
    • 지도 : com.google.android.apps.maps, com.google.android.maps.MapsActivity
    • 위치찾기 : com.google.android.apps.maps, com.google.android.maps.LatitudeActivity
    • YouTube : com.google.android.youtube, com.google.android.youtube.HomeActivity
    • 토크 : com.google.android.talk, com.google.android.talk.SigningInActivity
    • Goggles : com.google.android.apps.unveil, com.google.android.apps.unveil.CaptureActivity
    • Google 번역 : com.google.android.apps.translate, com.google.android.apps.translate.HomeActivity
    • Reader : com.google.android.apps.reader, com.google.android.apps.unveil.CaptureActivity
    • Voice : com.google.android.apps.googlevoice, com.google.android.apps.googlevoice.SplashActivity
    • Google 별지도 : com.google.android.stardroid, com.google.android.stardroid.activities.SplashScreenActivity
  • 카메라 : com.sec.android.app.camera, com.sec.android.app.camera.Camera

  • TV : com.sec.android.app.dmb, com.sec.android.app.dmb.activity.DMBFullScreenView

  • Android 관리

    • 환경 설정 : com.android.settings, com.android.settings.Settings
    • 작업 관리자 : com.sec.android.app.controlpanel, com.sec.android.app.controlpanel.activity.JobManagerActivity
  • 마켓 : com.android.vending, com.android.vending.AssetBrowserActivity


기타 사례

  • Intent 사례
 Intent intent = null;
 
 new Intent(ActivityExample.this, SimpleMathService.class);
 
 intent = new Intent(Intent.ACTION_VIEW);
 intent.setDataAndType(Uri.fromFile(new File("/sdcard/~.png")), "image/png");
 
 intent = new Intent(Intent.ACTION_GET_CONTENT);
 intent.setType("audio/*"); // image/*, video/*, vnd.android.cursor.item/phone_v2
  • ACTION
    • VIEW, INSERT, EDIT, DELETE
    • MAIN, PICK, GET_CONTENT

참고 문헌


분류: Android 오픈소스 Google Mobile

최종 수정일: 2022-10-24 19:17:28

이전글 :
다음글 :
상단 menu
arrow_back_ios
arrow_forward_ios