마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

SDK에 포함돼있는 NotePad 소스 예제 질문입니다

0 추천
case R.id.menu_add:
           startActivity(new Intent(Intent.ACTION_INSERT, getIntent().getData()));
           return true;
 
하.... 참 힘드네요 안드로이드공부 ㅠ_ㅠ 하지만 여러분들의 도움을 빌어 계속 나아가보겠습니다
 
일단 이부분이 암시적인텐트(implicit intent)라는건 알겠습니다!!
 
근데 책예제는 Intent.ACTION_DIAL, "전화번호" 나 Intent.ACTION_VIEW, "URL주소" 이런식이라 한눈에 확 들어오는데
 
NotePad예제 같은 경우에는 Intent.ACTION_INSERT 이부분도 명확하게 이해가 안갈뿐더러...
 
getIntent().getData() 이부분은 위에서 setData를 해줘서 content://com.google.provider.NotePad/notes이런 형태가
 
URI로 들어가 있습니다.  아래 매니페스트보면 NoteEditor에 유일하게 action.INSERT가 있더라구요
 
그리고 NoteEditor가 또 하나의 Activity인데요.
 
여기까지의 데이터로 제가 분석한 결과는 NoteEditor의 Activity에 content://com.google.provider.NotePad/notes 이 URI에 상응하는 정보를 적용해야되는게 아닌가라고 생각했습니다만 도저히 URI에 대한 정보를 찾을 수가 없습니다...
 
제가 혹시나 잘못이해하고 있거나 첨부한 소스 이외에 더 알아야될 부분이나 확인해봐야될 부분이 있다면 충고부탁드립니다.
 
매니페스트에서의 설정부분에 대한 내용을 첨부해보겠습니다
=================================================
 <activity android:name="NoteEditor"
            android:theme="@android:style/Theme.Holo.Light"
            android:screenOrientation="sensor"
            android:configChanges="keyboardHidden|orientation"
        >
                    ..............생략.................
 
            <intent-filter>
                <action android:name="android.intent.action.INSERT" />
                <action android:name="android.intent.action.PASTE" />
                <category android:name="android.intent.category.DEFAULT" />
                <data android:mimeType="vnd.android.cursor.dir/vnd.google.note" />
            </intent-filter>
 
        </activity>
 
 
api에 있는 Intent.ACTION_INSERT 설명 부분입니다
======================================
주어진 컨테이너에 빈 아이템을 넣어라...... 이게 무슨 의미인가요... 그 컨테이너가 NoteEditor인거 같은데 아이템은??ㅠㅠ

Activity Action: Insert an empty item into the given container.

Input: getData is URI of the directory (vnd.android.cursor.dir/*) in which to place the data.

Output: URI of the new data that was created.

 

반갑습니다 (310 포인트) 님이 2014년 6월 26일 질문

1개의 답변

+1 추천

Intent.ACTION.... 이라고 되어 있는 부분은 이런 이런 용도로 사용되는 인텐트로 미리 구글에서 정의해 놓은 Action 입니다.

ACTION_VIEW, data uri가 http://www.naver.com  이렇게 세팅 된 Intent로 startActiivty 하는 경우 해당 Intent를 처리할 수 있는 목록이 뜹니다.  보통 기본 브라우저, 크롬 브라우저, 혹은 다른 어플 목록들이 여러개 뜰꺼에요. 

그리고 같은 ACTION_VIEW로 data uri가 file:///sdcard/images/face.jpg  이런 형식으로 세팅 되면, 이미지를 읽어와서 보여줄 수 있는 어플리케이션 목록이 뜨게 됩니다. 갤러리, 이미지뷰어 같은 것들이요. 

그 어플에는 manifest 파일에 아래와 같이 해당 Intent를 처리 할 수 있도록 Intent filter 설정이 되어 있을꺼구요. 

<activity android:name=".ViewerActivity >

  <Intent-filter>

        <action android:name="android.intent.action.VIEW" />

        ... 

       <data android:mimeType="image/*" /> 

  </intent-filter> 

</activity>

 

NotePad에도 마찬가지로 ACTION_INSERT 를 처리하기 위한 intent-filter 가 manifest에 정의되어 있어요.

mineType의 경우 NotePadProvider의 getType() 함수를 확인해 보시면 될 것 같아요. 

<intent-filter>

                <action android:name="android.intent.action.INSERT" />
                <action android:name="android.intent.action.PASTE" />
                <category android:name="android.intent.category.DEFAULT" />
                <data android:mimeType="vnd.android.cursor.dir/vnd.google.note" />
</intent-filter>
 
위 Intent filter의 경우 
Intent action 은 ACTION_INSERT 혹은 ACTION_PASTE 이고
category는 DEFAULT ( Intent에 category 설정안하는 경우 DEFAULT)
data 는 content://com.google.provider.NotePad/notes 형식인 경우 해당 Intent를 받을 수 있도록 설정 되어 있는거에요. 
 
And (1,760 포인트) 님이 2014년 6월 26일 답변
소중한 답변 정말 감사합니다.
죄송하지만 아직 제가 이해가 잘 안되는데요.
content://com.google.provider.NotePad/notes 형식인 경우 해당 Intent를 받을 수 있도록 설정 되어 있는거에요.라고 하셨는데  해당 Intent가 어떤것인지는 어떻게 확인하나요?? 사이트나 이미지 같은 경우에는 해당 Intent가 다들 너무 잘 알고 있는 브라우저나 이미지 뷰어가 필요할 것이라는게 짐작이 되는데요....
아무튼 답변 정말 감사합니다!!
NotePadProvider 의 getType() 함수를 보시면 Uri 형태에 따라 type을 리턴하도록 구현되어 있는데, content://com.google.provider.NotePad/notes uri인 경우에는 "vnd.android.cursor.dir/vnd.google.note"을 type을 리턴하도록 구현되어 있어요.
와.... 저 드디어 이 부분 이해했습니다 ㅋㅋ
댓글달아주신거 몇번이고 읽어보면서 감동임 ㅠㅠ
감사합니다!!!
...