채택완료
안드로이드스튜디오 웹뷰 ChooseFile 클릭이 되지 않습니다.
안녕하세요! 안드로이드스튜디오 웹뷰를 통해 휴대폰에 있는 사진을 가져와 미리보기를 띄우고 싶은데, html에서 작업해서 만든 ChooseFile 버튼이 클릭조차 되지 않습니다 ㅜㅜ... iOS 로는 웹뷰를 가져왔을 때 문제없이 실행이 되는데 어디가 문제인지 구글링을 해도 나오지가않아서... 도와주시면 감사드리겠습니다!!! 코드입니다! MainActivity.java
Copy
package com.example.localhtml;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.webkit.WebSettings;
import android.webkit.WebViewClient;
import android.webkit.WebView;
public class MainActivity extends AppCompatActivity {
WebView webView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webView = findViewById(R.id.myWebView);
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setDatabaseEnabled(true);
webSettings.setBuiltInZoomControls(true);
webSettings.setDomStorageEnabled(true);
webSettings.setAllowFileAccess(true);
webSettings.setAllowContentAccess(true);
webView.setWebViewClient(new Callback());
webView.loadUrl("URL 입력하는 곳");
}
private class Callback extends WebViewClient{
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return false;
}
}
@Override
public void onBackPressed() {
if(webView != null && webView.canGoBack()) {
webView.goBack();
} else {
super.onBackPressed();
}
}
}
ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ
activity_main.xml
Copy
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@color/white">
<WebView
android:id="@+id/myWebView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"/>
</LinearLayout>
답변 1개 / 댓글 5개
채택된 답변
+20 포인트
저도 안드로이드는 잘은 모르는데 .. 제가 테스트할 용도로 만든 웹뷰가 하나 있긴한데 그거로 한번 대체해보고 되면 필요한 부분들만 빼가셔도 될거같아요
Copy
// MainActivity.java
package com.example.webviews;
import android.os.Build;
import android.annotation.SuppressLint;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class MainActivity extends AppCompatActivity {
private WebView mWebView; // 웹뷰 선언
private WebSettings mWebSettings; //웹뷰세팅
@Override
@SuppressLint("SetJavaScriptEnabled")
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// 웹뷰 시작
setContentView(R.layout.activity_main);
mWebView = (WebView) findViewById(R.id.webView);
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
mWebView.setWebViewClient(new WebViewClient()); // 클릭시 새창 안뜨게
// REMOTE RESOURCE
mWebView.loadUrl(""); // 웹뷰에 표시할 웹사이트 주소, 웹뷰 시작
}
@Override
public void onBackPressed() {
if(mWebView.canGoBack()) {
mWebView.goBack();
} else {
super.onBackPressed();
}
}
}
// activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<WebView
android:id="@+id/webView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true" >
</WebView>
</RelativeLayout>
답변에 대한 댓글 5개
https://github.com/googlearchive/chromium-webview-samples/blob/master/input-file-example/app/src/main/java/inputfilesample/android/chrome/google/com/inputfilesample/MainFragment.java#L76
이쯤코드부터 확인해보시는게 좋을거같네요 스택오버플로우에서 답변에 구글아카이브에서 가져왔다고 나와있네요
이쯤코드부터 확인해보시는게 좋을거같네요 스택오버플로우에서 답변에 구글아카이브에서 가져왔다고 나와있네요
답변을 작성하려면 로그인이 필요합니다.