Android Studio, Webview 2019
- 작은나눔/--안드로이드소스
- 2019. 8. 20. 11:11
반응형
2019 Webview
Android Studio 3.4.2
- MainActivity
package com.umcoop.*****;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import androidx.drawerlayout.widget.DrawerLayout;
import androidx.appcompat.app.ActionBar;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import static com.umcoop.*****.R.id.webView;
public class MainActivity extends AppCompatActivity {
private WebView mWebView;
private String mCurrentUrl;
private String myUrl = "URL";
Intent intent = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// 웹뷰 셋팅
mWebView = (WebView) findViewById(webView);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
mWebView.getSettings().setUseWideViewPort(true);
mWebView.getSettings().setLoadWithOverviewMode(true);
mWebView.setWebChromeClient(new WebChromeClient());
mWebView.setWebViewClient(new WebViewClientClass());
mWebView.loadUrl("file:///android_asset/index.html");
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack()) {
mWebView.goBack();
return true;
}
return super.onKeyDown(keyCode, event);
}
private class WebViewClientClass extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String overrideUrl) {
if (overrideUrl.startsWith("tel:") || overrideUrl.startsWith("sms:") || overrideUrl.startsWith("smsto:") || overrideUrl.startsWith("mms:") || overrideUrl.startsWith("mmsto:") || overrideUrl.startsWith("mailto:")) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(overrideUrl));
startActivity(intent);
return true;
}
view.loadUrl(overrideUrl);
return true;
}
}
}
- activiy_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.jerry.WebView.MainActivity">
<WebView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/webView"
>
</WebView>
</LinearLayout>
- AndroidManifest
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.CALL_PHONE" ></uses-permission>
<uses-permission android:name="android.permission.SEND_SMS"></uses-permission>
■ Reference
- assets
· File → New → Folder → Folder Assets
- Lunch Images, drawable
· File → New → Images Asset
· File → New → Vector Asset
반응형
'작은나눔 > --안드로이드소스' 카테고리의 다른 글
Android Studio, 2019, Back, twice, 앱 종료(두 번 뒤로가기) (0) | 2019.08.22 |
---|---|
og태그를 이용한 제목,이미지 제공 및 페이스북 썸네일 수정 (0) | 2015.08.19 |
webview , android_asset, www (0) | 2014.10.26 |
카카오 스토리, 카카오스토리 플러스, 스토리채널 링크 관련 (1) | 2014.09.21 |
parseSdkContent failed Could not initialize class android.graphics.Typeface 에러 (0) | 2014.09.20 |
[개발] 안드로이드 webview 기본 소스 (4) | 2014.07.26 |
[개발] 안드로이드 webview내 이동 (0) | 2014.07.26 |
[개발] 안드로이드 webview 뒤로가기 설정 (0) | 2014.07.26 |
[개발] 안드로이드 webview 기본속성 (0) | 2014.07.26 |
이 글을 공유하기