teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

4

意図的に内容を抹消する行為にあたるため

2021/06/29 05:18

投稿

退会済みユーザー
title CHANGED
@@ -1,1 +1,1 @@
1
- 質問を削除することしました
1
+ AndroidStudioのエミュレーターでWebVIewがネット繋がらない
body CHANGED
@@ -1,2 +1,157 @@
1
- 面倒だと思うなら回答なければいのはないでしょうかw
1
+ Android Studioでアプリ開発をる初心者す。
2
+ ネットで勉強しながら開発しているのですが、以下のサイトを参考にサンプルを作成したところエミュレーターでネットに繋がりませんでした。
3
+ 【参考にしたサンプルコード】
4
+ [https://akira-watson.com/android/webview.html](https://akira-watson.com/android/webview.html)
5
+ エミュレーターのブラウザ → 繋がらない
2
- 不要なサビスなで、全ての投稿内容を削除します
6
+ エミュレターWebView → 繋がらない
7
+ エラーメッセージ
8
+ ERR_NAME_NOT_RESOLVED
9
+ さらに他のサイトで調べて、DNSサーバを8.8.8.8にすると解決すると書いてあったので、試してみると
10
+ エミュレーターのブラウザ → 繋がる
11
+ エミュレーターのWebView → 繋がらない
12
+ エラーメッセージ
13
+ ERR_ACCESS_DENIED
14
+ 上記の通り、エミュレーターのブラウザではネットに接続できるようになり、エラーメッセージが変わりました。
15
+ WebViewでの接続ができるように調べていたのですが、いまだに解決に至らず、こちらに質問させて頂きました。
16
+ ぜひ、お力をお貸しください。
17
+ MainActivity.java
18
+ ```package com.example.testapp002;
19
+ import androidx.appcompat.app.AppCompatActivity;
20
+ import android.os.Bundle;
21
+ import android.content.Intent;
22
+ import android.net.Uri;
23
+ import android.view.KeyEvent;
24
+ import android.view.View;
25
+ import android.view.WindowManager;
26
+ import android.webkit.WebView;
27
+ import android.widget.Button;
28
+ public class MainActivity extends AppCompatActivity {
29
+ private WebView webView;
30
+ private String accessUrl = "https://akira-watson.com/";
31
+ @Override
32
+ protected void onCreate(Bundle savedInstanceState) {
33
+ super.onCreate(savedInstanceState);
34
+ setContentView(R.layout.activity_main);
35
+ Button button1 = findViewById(R.id.button_1);
36
+ Button button2 = findViewById(R.id.button_2);
37
+ // WebView
38
+ button1.setOnClickListener(new View.OnClickListener() {
39
+ @Override
40
+ public void onClick(View v) {
41
+ setContentView(R.layout.web);
42
+ webView = findViewById(R.id.web_view);
43
+ // JavaScriptを有効化
44
+ webView.getSettings().setJavaScriptEnabled(true);
45
+ // Web Storage を有効化
46
+ webView.getSettings().setDomStorageEnabled(true);
47
+ // Hardware Acceleration ON
48
+ getWindow().setFlags(
49
+ WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED,
50
+ WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);
51
+ webView.loadUrl(accessUrl);
52
+ }
53
+ });
54
+ // Browser
55
+ button2.setOnClickListener(new View.OnClickListener() {
56
+ @Override
57
+ public void onClick(View v) {
58
+ Uri uri = Uri.parse(accessUrl);
59
+ Intent intent = new Intent(Intent.ACTION_VIEW,uri);
60
+ startActivity(intent);
61
+ }
62
+ });
63
+ }
64
+ @Override
65
+ public boolean onKeyDown(int keyCode, KeyEvent event) {
66
+ // 戻るページがある場合
67
+ if (event.getAction() == KeyEvent.ACTION_DOWN
68
+ && keyCode == KeyEvent.KEYCODE_BACK){
69
+ if(webView.canGoBack()){
70
+ webView.goBack();
71
+ }
72
+ else{
73
+ finish();
74
+ }
75
+ return true;
76
+ }
77
+ return super.onKeyDown(keyCode, event);
78
+ }
79
+ }
80
+ ```
81
+ activity_main.xml
82
+ ```
83
+ <?xml version="1.0" encoding="utf-8"?>
84
+ <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
85
+ xmlns:tools="http://schemas.android.com/tools"
86
+ android:layout_width="match_parent"
87
+ android:layout_height="match_parent"
88
+ android:orientation="vertical"
89
+ android:gravity="center"
90
+ android:background="#dfe"
91
+ tools:context=".MainActivity">
92
+ <Button
93
+ android:id="@+id/button_1"
94
+ android:text="@string/button1"
95
+ android:layout_margin="20dp"
96
+ android:layout_width="match_parent"
97
+ android:layout_height="wrap_content"/>
98
+ <Button
99
+ android:id="@+id/button_2"
100
+ android:text="@string/button2"
101
+ android:layout_margin="20dp"
102
+ android:layout_width="match_parent"
103
+ android:layout_height="wrap_content"/>
104
+ </LinearLayout>
105
+ ```
106
+ AndroidManifest.xml
107
+ ```<?xml version="1.0" encoding="utf-8"?>
108
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android"
109
+ package="com.example.testapp002">
110
+ <uses-permission android:name="android.permission.INTERNET" />
111
+ <application
112
+ android:allowBackup="true"
113
+ android:icon="@mipmap/ic_launcher"
114
+ android:label="@string/app_name"
115
+ android:roundIcon="@mipmap/ic_launcher_round"
116
+ android:supportsRtl="true"
117
+ android:theme="@style/AppTheme"
118
+ android:usesCleartextTraffic="true"
119
+ >
120
+ <activity android:name=".MainActivity">
121
+ <intent-filter>
122
+ <action android:name="android.intent.action.MAIN" />
123
+ <category android:name="android.intent.category.LAUNCHER" />
124
+ </intent-filter>
125
+ </activity>
126
+ </application>
127
+ </manifest>
128
+ ```
129
+ web.xml
130
+ ```
131
+ <?xml version="1.0" encoding="utf-8"?>
132
+ <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
133
+ android:layout_width="match_parent"
134
+ android:layout_height="match_parent">
135
+ <WebView
136
+ android:id="@+id/web_view"
137
+ android:layout_width="match_parent"
138
+ android:layout_height="match_parent">
139
+ </WebView>
140
+ </LinearLayout>
141
+ ```
142
+ strings.xml
143
+ ```
144
+ <resources>
145
+ <string name="app_name">YourAppName</string>
146
+ <string name="button1">WebView</string>
147
+ <string name="button2">Browser</string>
148
+ </resources>
149
+ ```
150
+ エミュレーター
151
+ ![イメージ説明](4d3ac04e522d5326dcfdc72efd23d41e.png)
152
+ ビルド画面
153
+ ![イメージ説明](f4df843e1edc10363de41c37cc6cdd21.png)
154
+ エラーメッセージ
155
+ ![イメージ説明](5ffd8ee2f13b1ee5b3558fdc2079a30c.png)
156
+ Browser画面
157
+ ![イメージ説明](9185e154427df9693923e287ace09870.png)

3

質問削除します

2021/06/29 05:18

投稿

退会済みユーザー
title CHANGED
@@ -1,1 +1,1 @@
1
- AndroidStudioのエミュレーターでWebVIewがネット繋がらない
1
+ 質問を削除することしました
body CHANGED
@@ -1,213 +1,2 @@
1
- Android Studioでアプリ開発をる初心者す。
1
+ 面倒だと思うなら回答なければいのはないでしょうかw
2
-
3
- ネットで勉強しながら開発しているのですが、以下のサイトを参考にサンプルを作成したところエミュレーターでネットに繋がりませんでした。
4
-
5
-
6
- 【参考にしたサンプルコード】
7
- [https://akira-watson.com/android/webview.html](https://akira-watson.com/android/webview.html)
8
-
9
-
10
- エミュレーターのブラウザ → 繋がらない
11
- エミュレターのWebView → 繋がら
2
+ 不要なサビスので、全ての投稿内容を削除します
12
-
13
- エラーメッセージ
14
- ERR_NAME_NOT_RESOLVED
15
-
16
-
17
- さらに他のサイトで調べて、DNSサーバを8.8.8.8にすると解決すると書いてあったので、試してみると
18
-
19
-
20
- エミュレーターのブラウザ → 繋がる
21
- エミュレーターのWebView → 繋がらない
22
-
23
- エラーメッセージ
24
- ERR_ACCESS_DENIED
25
-
26
-
27
- 上記の通り、エミュレーターのブラウザではネットに接続できるようになり、エラーメッセージが変わりました。
28
-
29
-
30
- WebViewでの接続ができるように調べていたのですが、いまだに解決に至らず、こちらに質問させて頂きました。
31
-
32
-
33
- ぜひ、お力をお貸しください。
34
-
35
-
36
-
37
- MainActivity.java
38
- ```package com.example.testapp002;
39
-
40
- import androidx.appcompat.app.AppCompatActivity;
41
- import android.os.Bundle;
42
- import android.content.Intent;
43
- import android.net.Uri;
44
- import android.view.KeyEvent;
45
- import android.view.View;
46
- import android.view.WindowManager;
47
- import android.webkit.WebView;
48
- import android.widget.Button;
49
-
50
- public class MainActivity extends AppCompatActivity {
51
-
52
-
53
- private WebView webView;
54
- private String accessUrl = "https://akira-watson.com/";
55
-
56
- @Override
57
- protected void onCreate(Bundle savedInstanceState) {
58
- super.onCreate(savedInstanceState);
59
- setContentView(R.layout.activity_main);
60
-
61
- Button button1 = findViewById(R.id.button_1);
62
- Button button2 = findViewById(R.id.button_2);
63
-
64
- // WebView
65
- button1.setOnClickListener(new View.OnClickListener() {
66
- @Override
67
- public void onClick(View v) {
68
-
69
- setContentView(R.layout.web);
70
- webView = findViewById(R.id.web_view);
71
-
72
- // JavaScriptを有効化
73
- webView.getSettings().setJavaScriptEnabled(true);
74
-
75
- // Web Storage を有効化
76
- webView.getSettings().setDomStorageEnabled(true);
77
-
78
- // Hardware Acceleration ON
79
- getWindow().setFlags(
80
- WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED,
81
- WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);
82
-
83
- webView.loadUrl(accessUrl);
84
- }
85
- });
86
-
87
- // Browser
88
- button2.setOnClickListener(new View.OnClickListener() {
89
- @Override
90
- public void onClick(View v) {
91
- Uri uri = Uri.parse(accessUrl);
92
- Intent intent = new Intent(Intent.ACTION_VIEW,uri);
93
- startActivity(intent);
94
- }
95
- });
96
- }
97
-
98
- @Override
99
- public boolean onKeyDown(int keyCode, KeyEvent event) {
100
- // 戻るページがある場合
101
- if (event.getAction() == KeyEvent.ACTION_DOWN
102
- && keyCode == KeyEvent.KEYCODE_BACK){
103
- if(webView.canGoBack()){
104
- webView.goBack();
105
- }
106
- else{
107
- finish();
108
- }
109
- return true;
110
- }
111
-
112
- return super.onKeyDown(keyCode, event);
113
- }
114
- }
115
-
116
- ```
117
-
118
- activity_main.xml
119
- ```
120
- <?xml version="1.0" encoding="utf-8"?>
121
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
122
- xmlns:tools="http://schemas.android.com/tools"
123
- android:layout_width="match_parent"
124
- android:layout_height="match_parent"
125
- android:orientation="vertical"
126
- android:gravity="center"
127
- android:background="#dfe"
128
- tools:context=".MainActivity">
129
-
130
- <Button
131
- android:id="@+id/button_1"
132
- android:text="@string/button1"
133
- android:layout_margin="20dp"
134
- android:layout_width="match_parent"
135
- android:layout_height="wrap_content"/>
136
-
137
- <Button
138
- android:id="@+id/button_2"
139
- android:text="@string/button2"
140
- android:layout_margin="20dp"
141
- android:layout_width="match_parent"
142
- android:layout_height="wrap_content"/>
143
-
144
- </LinearLayout>
145
- ```
146
-
147
-
148
-
149
-
150
- AndroidManifest.xml
151
- ```<?xml version="1.0" encoding="utf-8"?>
152
- <manifest xmlns:android="http://schemas.android.com/apk/res/android"
153
- package="com.example.testapp002">
154
-
155
- <uses-permission android:name="android.permission.INTERNET" />
156
-
157
- <application
158
- android:allowBackup="true"
159
- android:icon="@mipmap/ic_launcher"
160
- android:label="@string/app_name"
161
- android:roundIcon="@mipmap/ic_launcher_round"
162
- android:supportsRtl="true"
163
- android:theme="@style/AppTheme"
164
- android:usesCleartextTraffic="true"
165
- >
166
- <activity android:name=".MainActivity">
167
- <intent-filter>
168
- <action android:name="android.intent.action.MAIN" />
169
-
170
- <category android:name="android.intent.category.LAUNCHER" />
171
- </intent-filter>
172
- </activity>
173
- </application>
174
-
175
- </manifest>
176
- ```
177
-
178
- web.xml
179
- ```
180
- <?xml version="1.0" encoding="utf-8"?>
181
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
182
- android:layout_width="match_parent"
183
- android:layout_height="match_parent">
184
- <WebView
185
- android:id="@+id/web_view"
186
- android:layout_width="match_parent"
187
- android:layout_height="match_parent">
188
- </WebView>
189
-
190
- </LinearLayout>
191
- ```
192
-
193
- strings.xml
194
- ```
195
- <resources>
196
- <string name="app_name">YourAppName</string>
197
- <string name="button1">WebView</string>
198
- <string name="button2">Browser</string>
199
- </resources>
200
-
201
- ```
202
-
203
- エミュレーター
204
- ![イメージ説明](4d3ac04e522d5326dcfdc72efd23d41e.png)
205
-
206
- ビルド画面
207
- ![イメージ説明](f4df843e1edc10363de41c37cc6cdd21.png)
208
-
209
- エラーメッセージ
210
- ![イメージ説明](5ffd8ee2f13b1ee5b3558fdc2079a30c.png)
211
-
212
- Browser画面
213
- ![イメージ説明](9185e154427df9693923e287ace09870.png)

2

誤字修正

2021/06/28 13:29

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -161,7 +161,7 @@
161
161
  android:roundIcon="@mipmap/ic_launcher_round"
162
162
  android:supportsRtl="true"
163
163
  android:theme="@style/AppTheme"
164
-
164
+ android:usesCleartextTraffic="true"
165
165
  >
166
166
  <activity android:name=".MainActivity">
167
167
  <intent-filter>

1

現在のソースの追記

2020/03/03 16:56

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -30,4 +30,184 @@
30
30
  WebViewでの接続ができるように調べていたのですが、いまだに解決に至らず、こちらに質問させて頂きました。
31
31
 
32
32
 
33
- ぜひ、お力をお貸しください。
33
+ ぜひ、お力をお貸しください。
34
+
35
+
36
+
37
+ MainActivity.java
38
+ ```package com.example.testapp002;
39
+
40
+ import androidx.appcompat.app.AppCompatActivity;
41
+ import android.os.Bundle;
42
+ import android.content.Intent;
43
+ import android.net.Uri;
44
+ import android.view.KeyEvent;
45
+ import android.view.View;
46
+ import android.view.WindowManager;
47
+ import android.webkit.WebView;
48
+ import android.widget.Button;
49
+
50
+ public class MainActivity extends AppCompatActivity {
51
+
52
+
53
+ private WebView webView;
54
+ private String accessUrl = "https://akira-watson.com/";
55
+
56
+ @Override
57
+ protected void onCreate(Bundle savedInstanceState) {
58
+ super.onCreate(savedInstanceState);
59
+ setContentView(R.layout.activity_main);
60
+
61
+ Button button1 = findViewById(R.id.button_1);
62
+ Button button2 = findViewById(R.id.button_2);
63
+
64
+ // WebView
65
+ button1.setOnClickListener(new View.OnClickListener() {
66
+ @Override
67
+ public void onClick(View v) {
68
+
69
+ setContentView(R.layout.web);
70
+ webView = findViewById(R.id.web_view);
71
+
72
+ // JavaScriptを有効化
73
+ webView.getSettings().setJavaScriptEnabled(true);
74
+
75
+ // Web Storage を有効化
76
+ webView.getSettings().setDomStorageEnabled(true);
77
+
78
+ // Hardware Acceleration ON
79
+ getWindow().setFlags(
80
+ WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED,
81
+ WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);
82
+
83
+ webView.loadUrl(accessUrl);
84
+ }
85
+ });
86
+
87
+ // Browser
88
+ button2.setOnClickListener(new View.OnClickListener() {
89
+ @Override
90
+ public void onClick(View v) {
91
+ Uri uri = Uri.parse(accessUrl);
92
+ Intent intent = new Intent(Intent.ACTION_VIEW,uri);
93
+ startActivity(intent);
94
+ }
95
+ });
96
+ }
97
+
98
+ @Override
99
+ public boolean onKeyDown(int keyCode, KeyEvent event) {
100
+ // 戻るページがある場合
101
+ if (event.getAction() == KeyEvent.ACTION_DOWN
102
+ && keyCode == KeyEvent.KEYCODE_BACK){
103
+ if(webView.canGoBack()){
104
+ webView.goBack();
105
+ }
106
+ else{
107
+ finish();
108
+ }
109
+ return true;
110
+ }
111
+
112
+ return super.onKeyDown(keyCode, event);
113
+ }
114
+ }
115
+
116
+ ```
117
+
118
+ activity_main.xml
119
+ ```
120
+ <?xml version="1.0" encoding="utf-8"?>
121
+ <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
122
+ xmlns:tools="http://schemas.android.com/tools"
123
+ android:layout_width="match_parent"
124
+ android:layout_height="match_parent"
125
+ android:orientation="vertical"
126
+ android:gravity="center"
127
+ android:background="#dfe"
128
+ tools:context=".MainActivity">
129
+
130
+ <Button
131
+ android:id="@+id/button_1"
132
+ android:text="@string/button1"
133
+ android:layout_margin="20dp"
134
+ android:layout_width="match_parent"
135
+ android:layout_height="wrap_content"/>
136
+
137
+ <Button
138
+ android:id="@+id/button_2"
139
+ android:text="@string/button2"
140
+ android:layout_margin="20dp"
141
+ android:layout_width="match_parent"
142
+ android:layout_height="wrap_content"/>
143
+
144
+ </LinearLayout>
145
+ ```
146
+
147
+
148
+
149
+
150
+ AndroidManifest.xml
151
+ ```<?xml version="1.0" encoding="utf-8"?>
152
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android"
153
+ package="com.example.testapp002">
154
+
155
+ <uses-permission android:name="android.permission.INTERNET" />
156
+
157
+ <application
158
+ android:allowBackup="true"
159
+ android:icon="@mipmap/ic_launcher"
160
+ android:label="@string/app_name"
161
+ android:roundIcon="@mipmap/ic_launcher_round"
162
+ android:supportsRtl="true"
163
+ android:theme="@style/AppTheme"
164
+
165
+ >
166
+ <activity android:name=".MainActivity">
167
+ <intent-filter>
168
+ <action android:name="android.intent.action.MAIN" />
169
+
170
+ <category android:name="android.intent.category.LAUNCHER" />
171
+ </intent-filter>
172
+ </activity>
173
+ </application>
174
+
175
+ </manifest>
176
+ ```
177
+
178
+ web.xml
179
+ ```
180
+ <?xml version="1.0" encoding="utf-8"?>
181
+ <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
182
+ android:layout_width="match_parent"
183
+ android:layout_height="match_parent">
184
+ <WebView
185
+ android:id="@+id/web_view"
186
+ android:layout_width="match_parent"
187
+ android:layout_height="match_parent">
188
+ </WebView>
189
+
190
+ </LinearLayout>
191
+ ```
192
+
193
+ strings.xml
194
+ ```
195
+ <resources>
196
+ <string name="app_name">YourAppName</string>
197
+ <string name="button1">WebView</string>
198
+ <string name="button2">Browser</string>
199
+ </resources>
200
+
201
+ ```
202
+
203
+ エミュレーター
204
+ ![イメージ説明](4d3ac04e522d5326dcfdc72efd23d41e.png)
205
+
206
+ ビルド画面
207
+ ![イメージ説明](f4df843e1edc10363de41c37cc6cdd21.png)
208
+
209
+ エラーメッセージ
210
+ ![イメージ説明](5ffd8ee2f13b1ee5b3558fdc2079a30c.png)
211
+
212
+ Browser画面
213
+ ![イメージ説明](9185e154427df9693923e287ace09870.png)