사이트가 HTTPS이지만 ERR_CLEARTEXT_NOT_PERMITTED를 표시하는 WebView
이 질문에 이미 답변이 있습니다.
Android에서 앱 작업을 시작하기 시작했기 때문에 많지 않습니다. 내가 가진 것은 지금까지 WebView뿐입니다. Android Studio에서 프로젝트를 만들었고 프로젝트가 Android InstantApp으로 설정되었습니다. 이유 / 방법은 잘 모르겠지만 프로젝트를 만들 때 옵션을 간과 한 것 같습니다.
WebView에서 net :: ERR_CLEARTEXT_NOT_PERMITTED라는 오류가 발생했습니다. 오류를 검색했을 때 앱이 InstantApp 일 때 WebViews는 HTTPS 사이트 만로드 할 수 있고 HTTP 사이트는로드 할 수 없다는 것을 알았습니다.
이 앱의 목적은 단 하나의 사이트를위한 매우 간단한 Flash 플레이어가되는 것입니다. 이것은 플래시가 필요한 게임을 더 나은 성능으로 실행하기 위함입니다. 이 게임은 HTTPS 인 darkorbit.com에 있습니다.
MainActivity.java :
package com.tylerr147.darkorbit;
import android.content.ComponentName;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WebView wv = findViewById(R.id.webView1);
wv.loadUrl("https://darkorbit.com/");
wv.setWebViewClient(new CustomWebViewClient());
WebSettings webSettings = wv.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setPluginState(WebSettings.PluginState.ON);
}
}
및 CustomWebViewClient.java
package com.tylerr147.darkorbit;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class CustomWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
내 질문 : 내 앱을 InstantApp으로 비활성화하려면 어떻게해야합니까? 또는이 WebView가 사이트를 표시하도록하려면 어떻게해야합니까?
몇 가지 다른 세부 정보도 언급하는 것이 중요하다고 생각합니다. WebView를 표시하는 앱에서 " http://darkorbit.com/ 의 웹 페이지 "를로드 할 수 없습니다. net :: ERR_CLEARTEXT_NOT_PERMITTED
Notice that is says "... site at http://darkorbit.com/ ...", and not "... site at https://darkorbit.com/ ..." even though the string for the URL is hardcoded, and says "https://darkorbit.com/". Also, I am testing the app on an emulator set up as a Google Pixel 2 running Android 9.
Any help would be appreciated. Thank you.
Solution:
Add the below line in your application
tag:
android:usesCleartextTraffic="true"
As shown below:
<application
....
android:usesCleartextTraffic="true"
....>
Hope it helps.
When you call "https://darkorbit.com/" your server figures that it's missing "www" so it redirects the call to "http://www.darkorbit.com/" and then to "https://www.darkorbit.com/", your WebView call is blocked at the first redirection as it's a "http" call. You can call "https://www.darkorbit.com/" instead and it will solve the issue.
'programing tip' 카테고리의 다른 글
'찾기'명령으로 수정 된 날짜 시간을 표시하는 방법은 무엇입니까? (0) | 2020.11.13 |
---|---|
ipython 서버를 시작할 수 없음 : notebook.notebookapp라는 모듈이 없습니다. (0) | 2020.11.13 |
자신의 Android 블루투스 트래픽 스니핑 / 로깅 (0) | 2020.11.12 |
ON CONFLICT 절에서 여러 충돌 대상 사용 (0) | 2020.11.12 |
Flutter : 상속 된 위젯을 올바르게 사용하는 방법? (0) | 2020.11.12 |