AndroidMenifest에서 Http URL intent filter 걸기

웹서비스와 앱서비스를 동시에 하는 유튜브와 같은 경우는

앱에서 해당 URL을 잡아서 앱으로 바로 띄울수도 있는 기능이 필요하다.

물론 앱을 띄우기 위해서 appScheme://execute 와 비슷한 scheme을 사용할 수 도 있지만,

해당 Scheme은 앱이 설치 되어있지 않은 단말에서는 무용지물이기 때문에

그것에 대비한 방법으로 아래 내용을 소개한다.


1. 목적
   - http 혹은 https URL의 링크 이동을 앱에서 직접 잡아서 앱을 띄울 수 있도록 처리한다.

2. 기본방법
   ※ 예시) http://www.myservice.com/ 이라는 URL로 이동시 앱을 띄우고자 할 때
   Step 1) AndroidMenifest.xml에서 해당 URL로 앱이 실행 될 경우 띄울 Activity에 아래와 같은 내용을 추가한다.
1
2
3
4
5
6
7
<intent-filter>
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />
        <data android:scheme="http"
              android:host="www.myservice.com"/>
</intent-filter>
cs
 
   Step 2) 해당 Activity의 Java Code에서 getIntent().getDataString()을 통해 진입경로를 확인 후 처리한다.

3. 응용
   ※ http://www.myservice.com일 경우는 웹페이지로 이동하지만,
      http://www.myservice.com?type=myApp인 경우는 App을 띄울 수 있게 하려면?
      (?뒤쪽으로 Parameter가 다양하게 추가될 수 있다고 가정한다.)

   
※ 기본 URL 구성
   

      - AndroidMenifest.xml에서 intent filter를 아래와 같이 추가한다.
        1) API Level 19 미만인 경우
          - 19 미만에서는 path와 ssp 구분이 따로 없다.
1
2
3
4
5
6
7
8
<intent-filter>
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />
    <data android:scheme="http"
          android:host="www.myservice.com"
           android:pathPattern=".*type=myApp.*"/>
</intent-filter>
cs
         ※ pathPattern=".*type=myApp.*" 에서 ".*"가 의미하는 것은 아래와 같다
             > '.' : 모든 문자들 중 1개가 존재한다.
             > '*' : 바로 앞 문자가 0개 이상 존재한다.
             > 즉, ".*"가 의미하는 것은 [어떤 문자가 0개 이상 존재한다] 라는 것

        2) API Level 19 이상인 경우
          - API Level이 19 이상인 경우는 path와 ssp 구분을 따로 해서 확인을 해줘야 한다.
            
http://www.myservice.com/scv/page.msc?param1=value1&type=myApp&param2=value2 인 경우 식별
1
2
3
4
5
6
7
8
9
<intent-filter>
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />
    <data android:scheme="http"
          android:host="www.myservice.com"
          android:pathPattern="/scv/page.msc"
          android:sscPattern=".*type=myApp.*"/>
</intent-filter>
cs
    ※ 참고 : http://developer.android.com/intl/ko/reference/android/R.attr.html#sspPattern

댓글

이 블로그의 인기 게시물

[Android] DataBinding의 동작방식 - 4. include Tag 혹은 ViewStub 사용시의 Binding

[Android] Retrofit2, OkHttpClient Method 정리

[Android] Layout별 성능 비교[Measure 호출횟수 비교] (LinearLayout vs RelativeLayout vs ConstraintLayout)