티스토리 뷰

program

[펌]Q_웹에서 어플 설치 여부 확인

littlecarbb 2015. 5. 18. 17:53

출처 : http://blog.naver.com/brainkorea/150146115713


--------------------------------------------------------


원글 : http://www.androidpub.com/index.php?mid=android_dev_qna&page=47&document_srl=1698272


1.앱이설치된 경우

 html에서 iframe 을 이용하여 앱을 호출하는걸 아이프레임에 넣어놓고 호출시에는 

 브라우저가 닫히고 앱이 실행되고

2.앱이 설치되지 않은 경우

 아이프레임상에서 오류페이지가 뜰경우 

 부모 html에 스크립트로 setTimeout 몇초간 줘서 

 브라우저가 

 0.5초동안 닫히지 않을시 어플다운로드 페이지로 이동하도록 해서 처리하였습니다.

 여기서 iframe 는 눈에 보이지 않도록 width=0 height=0 설정하였습니다.

 

<script>

function checkApplicationInstall() {

document.checkframe.location = "myapp://check_install";

setTimeout("checkApplicationInstall_callback()", 1000);

}


function checkApplicationInstall_callback() {

try {

var s = document.checkframe.document.body.innerHTML;

// 어플리케이션 설치되어있음

} catch (e) {

// 어플리케이션 설치 안 되어있음

}

}

</script>

<input type="button" value="check app install" onclick="checkApplicationInstall()"/><br/>

<iframe id="checkframe" name="checkframe" src="check.html" width="1" height="1"></iframe>

 

<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="myapp" android:host="check_install" />

</intent-filter>


---------------------------------------------------

checkApplicationInstall_callback 에서 전역변수 Intalled = true로 주어서

설치여부를 확인할 수도 있겠죠-



공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/02   »
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28
글 보관함