質問編集履歴
2
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -10,7 +10,9 @@
|
|
10
10
|
|
11
11
|
|
12
12
|
|
13
|
-
###コード
|
13
|
+
###コード・エラーまでの経緯
|
14
|
+
|
15
|
+
現在はこの様なコードになっているます。画像の読み込みが出来ないため、onActivityResultメソッドを取り組みたいと思います。
|
14
16
|
|
15
17
|
```java
|
16
18
|
|
@@ -232,7 +234,29 @@
|
|
232
234
|
|
233
235
|
//↓ここからを追加した際にエラー発生
|
234
236
|
|
237
|
+
//ここにonActivityResultコードを追加すると、、、
|
238
|
+
|
239
|
+
//ここまで
|
240
|
+
|
241
|
+
public class Callback extends WebViewClient {
|
242
|
+
|
243
|
+
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
|
244
|
+
|
245
|
+
Toast.makeText(getApplicationContext(), "Failed loading app!", Toast.LENGTH_SHORT).show();
|
246
|
+
|
247
|
+
}
|
248
|
+
|
249
|
+
}
|
250
|
+
|
251
|
+
}
|
252
|
+
|
253
|
+
```
|
254
|
+
|
255
|
+
付け加えるonActivityResultメソッドは以下になります。
|
256
|
+
|
257
|
+
```ここに言語を入力
|
258
|
+
|
235
|
-
|
259
|
+
@Override
|
236
260
|
|
237
261
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
238
262
|
|
@@ -274,20 +298,22 @@
|
|
274
298
|
|
275
299
|
}
|
276
300
|
|
277
|
-
//ここまで
|
278
|
-
|
279
|
-
public class Callback extends WebViewClient {
|
280
|
-
|
281
|
-
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
|
282
|
-
|
283
|
-
Toast.makeText(getApplicationContext(), "Failed loading app!", Toast.LENGTH_SHORT).show();
|
284
|
-
|
285
|
-
}
|
286
|
-
|
287
|
-
}
|
288
|
-
|
289
|
-
}
|
290
|
-
|
291
301
|
```
|
292
302
|
|
303
|
+
上記コードを付け加えると、INPUT_FILE_REQUEST_CODEがエラーになるため、
|
304
|
+
|
305
|
+
Create constant fieldをします。
|
306
|
+
|
307
|
+
|
308
|
+
|
309
|
+
![イメージ説明](a04c0244619e1926dfb3181dcbfde814.png)
|
310
|
+
|
311
|
+
|
312
|
+
|
313
|
+
そうすると下記の様に加えられますが、この時からビルドすると、表題のエラーが発生します。
|
314
|
+
|
315
|
+
![イメージ説明](75924cca2ed10a0c6dd20b21ac744dd1.png)
|
316
|
+
|
317
|
+
|
318
|
+
|
293
319
|
よろしくお願いします。
|
1
追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -14,7 +14,225 @@
|
|
14
14
|
|
15
15
|
```java
|
16
16
|
|
17
|
-
|
17
|
+
public class MainActivity extends AppCompatActivity {
|
18
|
+
|
19
|
+
private final static int FCR = 1;
|
20
|
+
|
21
|
+
private static final int INPUT_FILE_REQUEST_CODE = ;
|
22
|
+
|
23
|
+
WebView webView;
|
24
|
+
|
25
|
+
private String mCM;
|
26
|
+
|
27
|
+
private ValueCallback<Uri> mUM;
|
28
|
+
|
29
|
+
private ValueCallback<Uri[]> mUMA;
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
@Override
|
34
|
+
|
35
|
+
protected void onCreate(Bundle savedInstanceState) {
|
36
|
+
|
37
|
+
super.onCreate(savedInstanceState);
|
38
|
+
|
39
|
+
setContentView(R.layout.activity_main);
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
webView = findViewById(R.id.webview);
|
44
|
+
|
45
|
+
if (Build.VERSION.SDK_INT >= 23 && (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED)) {
|
46
|
+
|
47
|
+
ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.CAMERA}, 1);
|
48
|
+
|
49
|
+
}
|
50
|
+
|
51
|
+
assert webView != null;
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
WebSettings webSettings = webView.getSettings();
|
56
|
+
|
57
|
+
webSettings.setJavaScriptEnabled(true);
|
58
|
+
|
59
|
+
webSettings.setAllowFileAccess(true);
|
60
|
+
|
61
|
+
webView.getSettings().setLoadWithOverviewMode(true);
|
62
|
+
|
63
|
+
webView.getSettings().setUseWideViewPort(true);
|
64
|
+
|
65
|
+
webView.getSettings().setSupportZoom(true);
|
66
|
+
|
67
|
+
webView.getSettings().setBuiltInZoomControls(true);
|
68
|
+
|
69
|
+
if (Build.VERSION.SDK_INT >= 21) {
|
70
|
+
|
71
|
+
webSettings.setMixedContentMode(0);
|
72
|
+
|
73
|
+
webView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
|
74
|
+
|
75
|
+
} else if (Build.VERSION.SDK_INT >= 19) {
|
76
|
+
|
77
|
+
webView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
|
78
|
+
|
79
|
+
} else if (Build.VERSION.SDK_INT < 19) {
|
80
|
+
|
81
|
+
webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
|
82
|
+
|
83
|
+
}
|
84
|
+
|
85
|
+
webView.setWebViewClient(new Callback());
|
86
|
+
|
87
|
+
//webView.loadUrl("https://infeeds.com/");
|
88
|
+
|
89
|
+
webView.loadUrl("https://google.com");
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
webView.setWebChromeClient(new WebChromeClient() {
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
//For Android 3.0+
|
98
|
+
|
99
|
+
public void openFileChooser(ValueCallback<Uri> uploadMsg) {
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
mUM = uploadMsg;
|
104
|
+
|
105
|
+
Intent i = new Intent(Intent.ACTION_GET_CONTENT);
|
106
|
+
|
107
|
+
i.addCategory(Intent.CATEGORY_OPENABLE);
|
108
|
+
|
109
|
+
i.setType("*/*");
|
110
|
+
|
111
|
+
MainActivity.this.startActivityForResult(Intent.createChooser(i, "File Chooser"), FCR);
|
112
|
+
|
113
|
+
}
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
// For Android 3.0+, above method not supported in some android 3+ versions, in such case we use this
|
118
|
+
|
119
|
+
public void openFileChooser(ValueCallback uploadMsg, String acceptType) {
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
mUM = uploadMsg;
|
124
|
+
|
125
|
+
Intent i = new Intent(Intent.ACTION_GET_CONTENT);
|
126
|
+
|
127
|
+
i.addCategory(Intent.CATEGORY_OPENABLE);
|
128
|
+
|
129
|
+
i.setType("*/*");
|
130
|
+
|
131
|
+
MainActivity.this.startActivityForResult(
|
132
|
+
|
133
|
+
Intent.createChooser(i, "File Browser"),
|
134
|
+
|
135
|
+
FCR);
|
136
|
+
|
137
|
+
}
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
//For Android 4.1+
|
142
|
+
|
143
|
+
public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture) {
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
mUM = uploadMsg;
|
148
|
+
|
149
|
+
Intent i = new Intent(Intent.ACTION_GET_CONTENT);
|
150
|
+
|
151
|
+
i.addCategory(Intent.CATEGORY_OPENABLE);
|
152
|
+
|
153
|
+
i.setType("*/*");
|
154
|
+
|
155
|
+
MainActivity.this.startActivityForResult(Intent.createChooser(i, "File Chooser"), MainActivity.FCR);
|
156
|
+
|
157
|
+
}
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
//For Android 5.0+
|
162
|
+
|
163
|
+
public boolean onShowFileChooser(
|
164
|
+
|
165
|
+
WebView webView, ValueCallback<Uri[]> filePathCallback,
|
166
|
+
|
167
|
+
WebChromeClient.FileChooserParams fileChooserParams) {
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
if (mUMA != null) {
|
172
|
+
|
173
|
+
mUMA.onReceiveValue(null);
|
174
|
+
|
175
|
+
}
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
mUMA = filePathCallback;
|
180
|
+
|
181
|
+
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
|
182
|
+
|
183
|
+
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
Intent contentSelectionIntent = new Intent(Intent.ACTION_GET_CONTENT);
|
188
|
+
|
189
|
+
contentSelectionIntent.addCategory(Intent.CATEGORY_OPENABLE);
|
190
|
+
|
191
|
+
contentSelectionIntent.setType("*/*");
|
192
|
+
|
193
|
+
Intent[] intentArray;
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
if (takePictureIntent != null) {
|
198
|
+
|
199
|
+
intentArray = new Intent[]{takePictureIntent};
|
200
|
+
|
201
|
+
} else {
|
202
|
+
|
203
|
+
intentArray = new Intent[0];
|
204
|
+
|
205
|
+
}
|
206
|
+
|
207
|
+
|
208
|
+
|
209
|
+
Intent chooserIntent = new Intent(Intent.ACTION_CHOOSER);
|
210
|
+
|
211
|
+
chooserIntent.putExtra(Intent.EXTRA_INTENT, contentSelectionIntent);
|
212
|
+
|
213
|
+
chooserIntent.putExtra(Intent.EXTRA_TITLE, "Image Chooser");
|
214
|
+
|
215
|
+
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, intentArray);
|
216
|
+
|
217
|
+
startActivityForResult(chooserIntent, FCR);
|
218
|
+
|
219
|
+
|
220
|
+
|
221
|
+
return true;
|
222
|
+
|
223
|
+
}
|
224
|
+
|
225
|
+
|
226
|
+
|
227
|
+
});
|
228
|
+
|
229
|
+
|
230
|
+
|
231
|
+
}
|
232
|
+
|
233
|
+
//↓ここからを追加した際にエラー発生
|
234
|
+
|
235
|
+
@Override
|
18
236
|
|
19
237
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
20
238
|
|
@@ -56,6 +274,20 @@
|
|
56
274
|
|
57
275
|
}
|
58
276
|
|
277
|
+
//ここまで
|
278
|
+
|
279
|
+
public class Callback extends WebViewClient {
|
280
|
+
|
281
|
+
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
|
282
|
+
|
283
|
+
Toast.makeText(getApplicationContext(), "Failed loading app!", Toast.LENGTH_SHORT).show();
|
284
|
+
|
285
|
+
}
|
286
|
+
|
287
|
+
}
|
288
|
+
|
289
|
+
}
|
290
|
+
|
59
291
|
```
|
60
292
|
|
61
293
|
よろしくお願いします。
|