2014년 11월 17일 월요일

Android 웹 브라우저 링크로 앱 실행 방법

안드로이드 자체 브라우저로 특정 앱을 실행 하는 것이 가능하다.

이것은 안드로이드 OS가 가진 intent의 특징으로 가능 한것 같다.

Intent 의 자세한 내용은 안드로이드 API Guide에 있는  Intents and Intent Filters 를 보면 알수 있다.


1. 먼저 실행 하고자 하는 앱의 AndroidManifest.xml 파일에서 실행하고자 하는 Activity아래에 Intent-filter를 선언해준다.


<activity android:name="SearchActionActivity">
             <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="callMyApp" android:host="search"/>  
            </intent-filter>
</activity>


2. 웹 브라우저 상에서 링크 설정 방법
- 웹에서 특정 URL형태로 설정을 해줘야 해당 앱이 호출되어 실행 되어 진다.

<a href="callMyApp://search"> 나의 앱 검색 실행 </a>

위와같이 웹페이지에서 링크를 설정해 두면 해당 앱이 설치되어 있으면 해당 SearchActionActivity가 바로 실행 되어지는 걸 알수 있다.

따라서, 다른 액션의 Activity를 실행하고 싶다면 다른 Activity에 intent-filter만 추가해주면 가능하다.

<activity android:name="TakePhotoActionActivity">
             <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="callMyApp" android:host="takePhoto"/>  
            </intent-filter>
</activity>

웹에서 호출 방법은

<a href="callMyApp://takePhoto"> 나의 앱 사진 찍기 실행 </a>


3. 필요에 따라서 앱이 설치 되어 있으면 실행하고 설치 되어 있지 않으면 구글 플레이 마켓으로 이동 하고 싶다고 한다면 intent 전달 방식으로 호출 하면 된다.(Android Only)

기본 형식은 아래와 같다.

Intent://[host명]?파라미터=파리미터값
#Intent;scheme=callMyApp;action=android.intent.action.VIEW;category=android.intent.category.BROWSABLE;package=com.test.myapp;end


간단한 호출 예
<a href="Intent://takePhoto#Intent;scheme=callMyApp;package=com.test.myapp;end">
나의 앱 사진 찍기 실행 </a>




3. 앱에서 파라메터 값 받아서 처리 하기
- 앱에서 호출되어진 Activity 에서 Intent를 통해서 들어온 데이터에서 파라메터 값을 받아서 처리 할수도 있다.

Uri uriData = getIntent().getData();
String photoNumber = uriData.getQueryParameter("photoNumber ");

웹에서 호출
<a href="callMyApp://takePhoto?photoNumber=1"> 나의 앱 1번 사진 보기 </a>


이상으로 웹에서 링크로 안드로이드 앱의 호출을 알아보았습니다.

이것이 되는 것은 Android OS상에서 기본적으로 Intent 호출 방식을 지원하기 때문에 가능하지 않나 생각됩니다.



참고 사이트
http://developer.android.com/guide/components/intents-filters.html
http://developer.naver.com/wiki/pages/UrlScheme


댓글 1개:

  1. I feel really happy to have seen your webpage and look forward to so many more entertaining times reading here. Thanks once more for all the details.

    state employee cashless treatment scheme

    답글삭제