Contents

Views 7415 Comment 0
?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print
?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print

Javascript를 통해 Activity의 함수를 호출할 때,

예제는 finish();를 호출해서 현재 창을 닫는다.


Using the linked page as an example, you should be able to do something like this:

WebAppInterface class

public class WebAppInterface {
    Activity mActivity;

    /** Instantiate the interface and set the activity */
    WebAppInterface(Activity activity) {
        mActivity = activity;
    }

    /** Finish activity from the web page */
    @JavascriptInterface
    public void finishActivity() {
        mActivity.finish();
    }
}


Now, in your activity you add the JS interface like this:

WebViewActivity

WebView webView = (WebView) findViewById(R.id.webview);
webView.addJavascriptInterface(new WebAppInterface(this), "Android");


And in your webpage, you can finish the activity by clicking a button, like this:

HTML Contents

<input type="button" value="Finish the activity now" onClick="finishActivity()" />

<script type="text/javascript">
    function finishActivity() {
        Android.finishActivity();
    }
</script>

[출처] http://stackoverflow.com/questions/20639476/calling-activity-function-from-separate-class


?

  1. 무료로 HTTPS 적용하기 (Lets' Encrypt)

    Date2017.02.16 CategorySystem/OS Byhooni Views5912
    Read More
  2. [android] 초간단 HTTP, POST 전송 샘플

    Date2017.02.16 CategorySystem/OS Byhooni Views6474
    Read More
  3. Enable Safari Hidden Debug Menu in Mac OS X

    Date2017.02.07 CategorySystem/OS Byhooni Views7588
    Read More
  4. Enable the Develop Menu in Safari

    Date2017.02.07 CategorySystem/OS Byhooni Views4057
    Read More
  5. [ios] 동영상 플레이어 샘플 (for Remote Url)

    Date2017.02.07 CategoryDevelop Byhooni Views8166
    Read More
  6. [ios] 동영상 플레이어 샘플 (for Local File)

    Date2017.02.07 CategoryDevelop Byhooni Views7124
    Read More
  7. XML, JSON, BSON, MSGPACK 장,단점 비교

    Date2017.01.11 CategoryDevelop Byhooni Views6206
    Read More
  8. [ppt] 정보보호관리 발표내용 #2

    Date2016.12.08 CategoryPPT Byhooni Views4094
    Read More
  9. ISMS 인증기준 – 정보보호대책 (시스템개발보안)

    Date2016.12.01 CategoryEtc Byhooni Views3715
    Read More
  10. [ppt] 정보보호관리 발표내용

    Date2016.11.30 CategoryPPT Byhooni Views3213
    Read More
  11. 웹 보안 논문 주제 2016

    Date2016.11.28 CategoryEtc Byhooni Views0
    Read More
  12. [android] 버전 별 앱 알림 설정으로 이동하는 방법

    Date2016.11.28 CategoryDevelop Byhooni Views6031
    Read More
Board Pagination Prev 1 ... 6 7 8 9 10 11 12 13 14 15 ... 99 Next
/ 99