// webView.setWebChromeClient(((H5Activity) mContext).mOpenFileWebChromeClient);
webView.getSettings().setDomStorageEnabled(true);
webView.setWebViewClient(new WebViewClient() {
@ -734,6 +707,240 @@ public class HomeWebActivity extends Activity implements View.OnClickListener, P
super.onPause();
MobclickAgent.onPause(this);
}
@Override
public void onRequestPermissionsResult(int requestCode,
@NonNull String[] permissions,
@NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
// EasyPermissions handles the request result.
EasyPermissions.onRequestPermissionsResult(requestCode, permissions, grantResults, this);
}
@Override
public void onPermissionsGranted(int requestCode, List<String> perms) {
}
@Override
public void onPermissionsDenied(int requestCode, List<String> perms) {
}
public class OpenFileWebChromeClient extends WebChromeClient {
public static final int REQUEST_FILE_PICKER = 1;
public ValueCallback<Uri> mFilePathCallback;
public ValueCallback<Uri[]> mFilePathCallbacks;
Activity mContext;
public OpenFileWebChromeClient(Activity mContext) {
super();
this.mContext = mContext;
}
@Override
public void onReceivedTitle(WebView view, String title) {
super.onReceivedTitle(view, title);
Log.d("ANDROID_LAB", "TITLE=" + title);
txtTitle.setText(title);
}
@Override
public void onProgressChanged(WebView view, int newProgress) {
super.onProgressChanged(view, newProgress);
// pb_webBar.setProgress(newProgress);
}
@Override
public void onGeolocationPermissionsShowPrompt(String origin,
GeolocationPermissions.Callback callback) {
callback.invoke(origin, true, false);
// TODO Auto-generated method stub
super.onGeolocationPermissionsShowPrompt(origin, callback);
}
// Android < 3.0 调用这个方法
public void openFileChooser(ValueCallback<Uri> filePathCallback) {
mFilePathCallback = filePathCallback;
permissionTask();
}
// 3.0 + 调用这个方法
public void openFileChooser(ValueCallback filePathCallback, String acceptType) {
mFilePathCallback = filePathCallback;
permissionTask();
}
// / js上传文件的<input type="file" name="fileField" id="fileField" />事件捕获
// Android > 4.1.1 调用这个方法
public void openFileChooser(ValueCallback<Uri> filePathCallback, String acceptType, String capture) {
mFilePathCallback = filePathCallback;
permissionTask();
}
@Override
public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback, FileChooserParams fileChooserParams) {
mFilePathCallbacks = filePathCallback;
permissionTask();
return true;
}
}
@AfterPermissionGranted(RC_ALBUM_PERM)
public void permissionTask() {
if (isPermissionOK()) {
openImageChooserActivity();
} else {
EasyPermissions.requestPermissions(
this, "充电桩想要获取您的图片读取权限,是否允许?",
RC_ALBUM_PERM,
Manifest.permission.CAMERA,
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.READ_EXTERNAL_STORAGE);
}
}
private boolean isPermissionOK() {
return EasyPermissions.hasPermissions(this,
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.CAMERA
);
}
private void openImageChooserActivity() {
new MaterialDialog.Builder(this).items(R.array.photo).positiveText("取消")
.onPositive(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
if (mOpenFileWebChromeClient.mFilePathCallbacks != null) {
mOpenFileWebChromeClient.mFilePathCallbacks.onReceiveValue(null);
mOpenFileWebChromeClient.mFilePathCallbacks = null;
}
if (mOpenFileWebChromeClient.mFilePathCallback != null) {
mOpenFileWebChromeClient.mFilePathCallback.onReceiveValue(null);
mOpenFileWebChromeClient.mFilePathCallback = null;
}
dialog.dismiss();
}
}).cancelable(false)
.canceledOnTouchOutside(false).itemsCallback(new MaterialDialog.ListCallback() {
@Override
public void onSelection(MaterialDialog dialog, View itemView, int position, CharSequence text) {
if (position == 0){
takeCamera();
} else if (position == 1) {
takePhoto();
}
}
}).show();
}
// 选择图片
private void takePhoto() {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("image/*");
startActivityForResult(Intent.createChooser(intent, "Image Choose"), FILE_CHOOSER_RESULT_CODE);
}
// 拍照
private void takeCamera() {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (ImageUitl.hasSdcard()) {
String fileName = "android" + System.currentTimeMillis() / 1000 + ".jpg";
cameraFilePath = ImageUitl.getPath(Environment.getExternalStorageDirectory() + "/" + "cdz") + "/" + fileName;
File imageFile = ImageUitl.getFile(cameraFilePath);
Uri uri = parseUri(imageFile);
intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
try{
startActivityForResult(intent, FILE_CAMERA_RESULT_CODE);
} catch (Exception e) {
e.printStackTrace();
}
}
}
private Uri parseUri(File cameraFile) {
Uri imageUri;
String authority = getPackageName() + ".provider";
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
//通过FileProvider创建一个content类型的Uri
imageUri = FileProvider.getUriForFile(getApplicationContext(), authority, cameraFile);
} else {
imageUri = Uri.fromFile(cameraFile);
}
return imageUri;
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (null == mOpenFileWebChromeClient.mFilePathCallback && null == mOpenFileWebChromeClient.mFilePathCallbacks) return;
if (resultCode != RESULT_OK) {
if (mOpenFileWebChromeClient.mFilePathCallbacks != null) {
mOpenFileWebChromeClient.mFilePathCallbacks.onReceiveValue(null);
mOpenFileWebChromeClient.mFilePathCallbacks = null;
}
if (mOpenFileWebChromeClient.mFilePathCallback != null) {
mOpenFileWebChromeClient.mFilePathCallback.onReceiveValue(null);
mOpenFileWebChromeClient.mFilePathCallback = null;
}
return;
}
Uri result = null;
if (requestCode == FILE_CAMERA_RESULT_CODE) {
if (null != data && null != data.getData()) {
result = data.getData();
}
if (result == null && ImageUitl.hasFile(cameraFilePath)) {
result = Uri.fromFile(new File(cameraFilePath));
}
if (mOpenFileWebChromeClient.mFilePathCallbacks != null) {
mOpenFileWebChromeClient.mFilePathCallbacks.onReceiveValue(new Uri[]{result});
mOpenFileWebChromeClient.mFilePathCallbacks = null;
} else if (mOpenFileWebChromeClient.mFilePathCallback != null) {
mOpenFileWebChromeClient.mFilePathCallback.onReceiveValue(result);
mOpenFileWebChromeClient.mFilePathCallback = null;
}
} else if (requestCode == FILE_CHOOSER_RESULT_CODE) {
if (data != null) {
result = data.getData();
}
if (mOpenFileWebChromeClient.mFilePathCallbacks != null) {
onActivityResultCallbacks(data);
} else if (mOpenFileWebChromeClient.mFilePathCallback != null) {
mOpenFileWebChromeClient.mFilePathCallback.onReceiveValue(result);
mOpenFileWebChromeClient.mFilePathCallback = null;
}
}
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void onActivityResultCallbacks(Intent intent) {
Uri[] results = null;
if (intent != null) {
String dataString = intent.getDataString();
ClipData clipData = intent.getClipData();
if (clipData != null) {
results = new Uri[clipData.getItemCount()];
for (int i=0;i<clipData.getItemCount();i++) {
ClipData.Item item = clipData.getItemAt(i);
results[i] = item.getUri();
}
}
if (dataString != null) {
results = new Uri[] {Uri.parse(dataString)};
}
mOpenFileWebChromeClient.mFilePathCallbacks.onReceiveValue(results);
mOpenFileWebChromeClient.mFilePathCallbacks = null;
}
}
}
|
||
| 5548 | 5548 |
|
| 5549 | 5549 |
|
| 5550 | 5550 |
|
| 5551 |
|
|
| 5552 |
|
|
| 5551 | 5553 |
|
| 5552 | 5554 |
|
| 5553 | 5555 |
|
|
||
| 16 | 16 |
|
| 17 | 17 |
|
| 18 | 18 |
|
| 19 |
|
|
| 19 | 20 |
|
| 21 |
|
|
| 22 |
|
|
| 23 |
|
|
| 20 | 24 |
|
| 21 | 25 |
|
| 22 | 26 |
|
|
||
| 27 | 31 |
|
| 28 | 32 |
|
| 29 | 33 |
|
| 34 |
|
|
| 30 | 35 |
|
| 31 | 36 |
|
| 32 | 37 |
|
|
||
| 35 | 40 |
|
| 36 | 41 |
|
| 37 | 42 |
|
| 43 |
|
|
| 44 |
|
|
| 38 | 45 |
|
| 39 | 46 |
|
| 40 | 47 |
|
|
||
| 43 | 50 |
|
| 44 | 51 |
|
| 45 | 52 |
|
| 53 |
|
|
| 46 | 54 |
|
| 47 | 55 |
|
| 48 | 56 |
|
|
||
| 95 | 103 |
|
| 96 | 104 |
|
| 97 | 105 |
|
| 106 |
|
|
| 107 |
|
|
| 108 |
|
|
| 109 |
|
|
| 110 |
|
|
| 98 | 111 |
|
| 99 | 112 |
|
| 100 | 113 |
|
|
||
| 160 | 173 |
|
| 161 | 174 |
|
| 162 | 175 |
|
| 176 |
|
|
| 177 |
|
|
| 178 |
|
|
| 163 | 179 |
|
| 164 | 180 |
|
| 165 | 181 |
|
|
||
| 1219 | 1235 |
|
| 1220 | 1236 |
|
| 1221 | 1237 |
|
| 1238 |
|
|
| 1239 |
|
|
| 1240 |
|
|
| 1241 |
|
|
| 1242 |
|
|
| 1243 |
|
|
| 1244 |
|
|
| 1245 |
|
|
| 1246 |
|
|
| 1247 |
|
|
| 1222 | 1248 |
|
| 1223 | 1249 |
|
| 1224 | 1250 |
|
| 1225 | 1251 |
|
| 1226 | 1252 |
|
| 1227 | 1253 |
|
| 1228 |
|
|
| 1229 |
|
|
| 1230 |
|
|
| 1254 |
|
|
| 1255 |
|
|
| 1256 |
|
|
| 1231 | 1257 |
|
| 1258 |
|
|
| 1259 |
|
|
| 1260 |
|
|
| 1261 |
|
|
| 1232 | 1262 |
|
| 1233 | 1263 |
|
| 1234 | 1264 |
|
|
||
| 1270 | 1300 |
|
| 1271 | 1301 |
|
| 1272 | 1302 |
|
| 1273 |
|
|
| 1274 |
|
|
| 1275 |
|
|
| 1276 |
|
|
| 1277 |
|
|
| 1278 |
|
|
| 1303 |
|
|
| 1279 | 1304 |
|
| 1280 | 1305 |
|
| 1281 | 1306 |
|
| 1282 |
|
|
| 1283 |
|
|
| 1307 |
|
|
| 1284 | 1308 |
|
| 1285 |
|
|
| 1286 |
|
|
| 1287 |
|
|
| 1288 |
|
|
| 1289 |
|
|
| 1290 |
|
|
| 1309 |
|
|
| 1291 | 1310 |
|
| 1292 | 1311 |
|
| 1293 | 1312 |
|
| 1294 | 1313 |
|
| 1295 |
|
|
| 1296 |
|
|
| 1314 |
|
|
| 1297 | 1315 |
|
| 1298 |
|
|
| 1299 |
|
|
| 1300 |
|
|
| 1301 |
|
|
| 1302 |
|
|
| 1303 |
|
|
| 1316 |
|
|
| 1304 | 1317 |
|
| 1305 | 1318 |
|
| 1306 |
|
|
| 1307 |
|
|
| 1319 |
|
|
| 1320 |
|
|
| 1308 | 1321 |
|
| 1309 |
|
|
| 1310 |
|
|
| 1311 |
|
|
| 1312 |
|
|
| 1313 |
|
|
| 1314 |
|
|
| 1322 |
|
|
| 1315 | 1323 |
|
| 1316 | 1324 |
|
| 1317 | 1325 |
|
| 1318 | 1326 |
|
| 1327 |
|
|
| 1328 |
|
|
| 1329 |
|
|
| 1330 |
|
|
| 1331 |
|
|
| 1332 |
|
|
| 1333 |
|
|
| 1334 |
|
|
| 1335 |
|
|
| 1336 |
|
|
| 1337 |
|
|
| 1338 |
|
|
| 1339 |
|
|
| 1340 |
|
|
| 1341 |
|
|
| 1342 |
|
|
| 1343 |
|
|
| 1344 |
|
|
| 1345 |
|
|
| 1346 |
|
|
| 1347 |
|
|
| 1348 |
|
|
| 1349 |
|
|
| 1350 |
|
|
| 1351 |
|
|
| 1352 |
|
|
| 1353 |
|
|
| 1354 |
|
|
| 1355 |
|
|
| 1356 |
|
|
| 1357 |
|
|
| 1358 |
|
|
| 1359 |
|
|
| 1360 |
|
|
| 1361 |
|
|
| 1362 |
|
|
| 1363 |
|
|
| 1364 |
|
|
| 1365 |
|
|
| 1366 |
|
|
| 1367 |
|
|
| 1368 |
|
|
| 1369 |
|
|
| 1370 |
|
|
| 1371 |
|
|
| 1372 |
|
|
| 1373 |
|
|
| 1374 |
|
|
| 1375 |
|
|
| 1376 |
|
|
| 1377 |
|
|
| 1378 |
|
|
| 1379 |
|
|
| 1380 |
|
|
| 1381 |
|
|
| 1382 |
|
|
| 1383 |
|
|
| 1384 |
|
|
| 1385 |
|
|
| 1386 |
|
|
| 1387 |
|
|
| 1388 |
|
|
| 1389 |
|
|
| 1390 |
|
|
| 1391 |
|
|
| 1392 |
|
|
| 1393 |
|
|
| 1394 |
|
|
| 1395 |
|
|
| 1396 |
|
|
| 1397 |
|
|
| 1398 |
|
|
| 1399 |
|
|
| 1400 |
|
|
| 1401 |
|
|
| 1402 |
|
|
| 1403 |
|
|
| 1404 |
|
|
| 1405 |
|
|
| 1406 |
|
|
| 1407 |
|
|
| 1408 |
|
|
| 1409 |
|
|
| 1410 |
|
|
| 1411 |
|
|
| 1412 |
|
|
| 1413 |
|
|
| 1414 |
|
|
| 1415 |
|
|
| 1319 | 1416 |
|
| 1320 | 1417 |
|
| 1321 | 1418 |
|
|
||
| 1366 | 1463 |
|
| 1367 | 1464 |
|
| 1368 | 1465 |
|
| 1369 |
|
|
| 1370 |
|
|
| 1466 |
|
|
| 1467 |
|
|
| 1468 |
|
|
| 1469 |
|
|
| 1470 |
|
|
| 1471 |
|
|
| 1472 |
|
|
| 1473 |
|
|
| 1474 |
|
|
| 1371 | 1475 |
|
| 1372 |
|
|
| 1373 |
|
|
| 1374 |
|
|
| 1375 |
|
|
| 1376 |
|
|
| 1377 |
|
|
| 1378 |
|
|
| 1379 |
|
|
| 1380 |
|
|
| 1381 |
|
|
| 1382 |
|
|
| 1383 |
|
|
| 1476 |
|
|
| 1477 |
|
|
| 1384 | 1478 |
|
| 1479 |
|
|
| 1480 |
|
|
| 1481 |
|
|
| 1482 |
|
|
| 1483 |
|
|
| 1484 |
|
|
| 1485 |
|
|
| 1486 |
|
|
| 1487 |
|
|
| 1488 |
|
|
| 1489 |
|
|
| 1490 |
|
|
| 1385 | 1491 |
|
| 1386 |
|
|
| 1387 |
|
|
| 1388 |
|
|
| 1389 |
|
|
| 1390 |
|
|
| 1391 |
|
|
| 1392 |
|
|
| 1393 |
|
|
| 1394 |
|
|
| 1395 |
|
|
| 1396 |
|
|
| 1397 |
|
|
| 1492 |
|
|
| 1493 |
|
|
| 1494 |
|
|
| 1495 |
|
|
| 1496 |
|
|
| 1497 |
|
|
| 1498 |
|
|
| 1499 |
|
|
| 1500 |
|
|
| 1501 |
|
|
| 1502 |
|
|
| 1503 |
|
|
| 1504 |
|
|
| 1505 |
|
|
| 1506 |
|
|
| 1398 | 1507 |
|
| 1508 |
|
|
| 1509 |
|
|
| 1399 | 1510 |
|
| 1400 |
|
|
| 1511 |
|
|
| 1512 |
|
|
| 1513 |
|
|
| 1514 |
|
|
| 1515 |
|
|
| 1516 |
|
|
| 1517 |
|
|
| 1518 |
|
|
| 1519 |
|
|
| 1520 |
|
|
| 1521 |
|
|
| 1522 |
|
|
| 1523 |
|
|
| 1524 |
|
|
| 1525 |
|
|
| 1526 |
|
|
| 1527 |
|
|
| 1401 | 1528 |
|
| 1402 | 1529 |
|
| 1403 | 1530 |
|
|
||
| 7 | 7 |
|
| 8 | 8 |
|
| 9 | 9 |
|
| 10 |
|
|
| 10 | 11 |
|
| 11 | 12 |
|
| 12 | 13 |
|
| 13 | 14 |
|
| 14 | 15 |
|
| 16 |
|
|
| 15 | 17 |
|
| 16 | 18 |
|
| 17 | 19 |
|
|
||
| 396 | 398 |
|
| 397 | 399 |
|
| 398 | 400 |
|
| 401 |
|
|
| 402 |
|
|
| 403 |
|
|
| 404 |
|
|
| 405 |
|
|
| 406 |
|
|
| 407 |
|
|
| 408 |
|
|
| 409 |
|
|
| 410 |
|
|
| 411 |
|
|
| 412 |
|
|
| 413 |
|
|
| 414 |
|
|
| 415 |
|
|
| 416 |
|
|
| 417 |
|
|
| 418 |
|
|
| 419 |
|
|
| 420 |
|
|
| 421 |
|
|
| 422 |
|
|
| 423 |
|
|
| 424 |
|
|
| 425 |
|
|
| 426 |
|
|
| 427 |
|
|
| 428 |
|
|
| 429 |
|
|
| 430 |
|
|
| 431 |
|
|
| 432 |
|
|
| 433 |
|
|
| 434 |
|
|
| 435 |
|
|
| 436 |
|
|
| 437 |
|
|
| 438 |
|
|
| 439 |
|
|
| 440 |
|
|
| 441 |
|
|
| 399 | 442 |
|
|
||
| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
|
| 21 |
|
|
| 22 |
|
|
| 23 |
|
|
| 24 |
|
|
| 25 |
|
|
| 26 |
|
|
| 27 |
|
|
| 28 |
|
|
| 29 |
|
|
| 30 |
|
|
| 31 |
|
|
| 32 |
|
|
| 33 |
|
|
| 34 |
|
|
| 35 |
|
|
| 36 |
|
|
| 37 |
|
|
| 38 |
|
|
| 39 |
|
|
| 40 |
|
|
| 41 |
|
|
| 42 |
|
|
| 43 |
|
|
| 44 |
|
|
| 45 |
|
|
| 46 |
|
|
| 47 |
|
|
| 48 |
|
|
| 49 |
|
|
| 50 |
|
|
| 51 |
|
|
| 52 |
|
|
| 53 |
|
|
| 54 |
|
|
| 55 |
|
|
| 56 |
|
|
| 57 |
|
|
| 58 |
|
|
| 59 |
|
|
| 60 |
|
|
| 61 |
|
|
| 62 |
|
|
| 63 |
|
|
| 64 |
|
|
| 65 |
|
|
| 66 |
|
|
| 67 |
|
|
| 68 |
|
|
| 69 |
|
|
| 70 |
|
|
| 71 |
|
|
| 72 |
|
|
|
||
| 13 | 13 |
|
| 14 | 14 |
|
| 15 | 15 |
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 16 | 20 |
|
| 17 | 21 |
|
| 18 | 22 |
|