: intent.getData();
1368
                if (result != null) {
1369
                    String path = MediaUtility.getPath(getApplicationContext(),
1370
                            result);
1371
                    Uri uri = Uri.fromFile(new File(path));
1372
                    mOpenFileWebChromeClient.mFilePathCallbacks
1373
                            .onReceiveValue(new Uri[]{uri});
1374
                } else {
1375
                    mOpenFileWebChromeClient.mFilePathCallbacks
1376
                            .onReceiveValue(null);
1377
                }
1472
                mOpenFileWebChromeClient.mFilePathCallbacks.onReceiveValue(new Uri[]{result});
1473
                mOpenFileWebChromeClient.mFilePathCallbacks = null;
1474
            } else if (mOpenFileWebChromeClient.mFilePathCallback != null) {
1475
                mOpenFileWebChromeClient.mFilePathCallback.onReceiveValue(result);
1476
                mOpenFileWebChromeClient.mFilePathCallback = null;
1477
            }
1478
        } else if (requestCode == FILE_CHOOSER_RESULT_CODE) {
1479
            if (data != null) {
1480
                result = data.getData();
1481
            }
1482
            if (mOpenFileWebChromeClient.mFilePathCallbacks != null) {
1483
                onActivityResultCallbacks(data);
1484
            } else if (mOpenFileWebChromeClient.mFilePathCallback != null) {
1485
                mOpenFileWebChromeClient.mFilePathCallback.onReceiveValue(result);
1486
                mOpenFileWebChromeClient.mFilePathCallback = null;
1378 1487
            }
1488
        }
1489
    }
1379 1490
1380
            mOpenFileWebChromeClient.mFilePathCallback = null;
1491
    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
1492
    private void onActivityResultCallbacks(Intent intent) {
1493
        Uri[] results = null;
1494
        if (intent != null) {
1495
            String dataString = intent.getDataString();
1496
            ClipData clipData = intent.getClipData();
1497
            if (clipData != null) {
1498
                results = new Uri[clipData.getItemCount()];
1499
                for (int i=0;i<clipData.getItemCount();i++) {
1500
                    ClipData.Item item = clipData.getItemAt(i);
1501
                    results[i] = item.getUri();
1502
                }
1503
            }
1504
            if (dataString != null) {
1505
                results = new Uri[] {Uri.parse(dataString)};
1506
            }
1507
            mOpenFileWebChromeClient.mFilePathCallbacks.onReceiveValue(results);
1381 1508
            mOpenFileWebChromeClient.mFilePathCallbacks = null;
1382 1509
        }
1383 1510
    }

+ 43 - 0
app/src/main/java/com/electric/chargingpile/util/ImageUitl.java

@ -7,11 +7,13 @@ import android.graphics.Bitmap;
7 7
import android.graphics.BitmapFactory;
8 8
import android.graphics.Matrix;
9 9
import android.net.Uri;
10
import android.os.Environment;
10 11
import android.util.Log;
11 12
12 13
import java.io.ByteArrayInputStream;
13 14
import java.io.ByteArrayOutputStream;
14 15
import java.io.File;
16
import java.io.IOException;
15 17
import java.io.InputStream;
16 18
17 19
/**
@ -396,4 +398,45 @@ public class ImageUitl {
396 398
        bitmap = compressImage(bitmap, 100);//质量压缩
397 399
        return bitmap;
398 400
    }
401
402
    public static boolean hasSdcard() {
403
        if (android.os.Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
404
            return true;
405
        } else {
406
            return false;
407
        }
408
    }
409
410
    public static String getPath(String path) {
411
        File f = new File(path);
412
        if (!f.exists()) {
413
            f.mkdirs();
414
        }
415
        return f.getAbsolutePath();
416
    }
417
418
    public static File getFile(String path) {
419
        File f = new File(path);
420
        if (!f.exists()) {
421
            try {
422
                f.createNewFile();
423
            } catch (IOException e) {
424
                e.printStackTrace();
425
            }
426
        }
427
        return f;
428
    }
429
430
    public static boolean hasFile(String path) {
431
        try {
432
            File f = new File(path);
433
            if (!f.exists()) {
434
                return false;
435
            }
436
        } catch (Exception e) {
437
            return false;
438
        }
439
        return true;
440
    }
441
399 442
}

+ 0 - 72
app/src/main/java/com/electric/chargingpile/util/OpenFileWebChromeClient.java

@ -1,72 +0,0 @@
1
package com.electric.chargingpile.util;
2
3
import android.app.Activity;
4
import android.content.Intent;
5
import android.net.Uri;
6
import android.webkit.ValueCallback;
7
import android.webkit.WebChromeClient;
8
import android.webkit.WebView;
9
10
/**
11
 * Created by Demon on 16/7/19.
12
 */
13
14
public class OpenFileWebChromeClient extends WebChromeClient {
15
    public static final int REQUEST_FILE_PICKER = 1;
16
    public ValueCallback<Uri> mFilePathCallback;
17
    public ValueCallback<Uri[]> mFilePathCallbacks;
18
    Activity mContext;
19
20
    public OpenFileWebChromeClient(Activity mContext) {
21
        super();
22
        this.mContext = mContext;
23
    }
24
25
    // Android < 3.0 调用这个方法
26
    public void openFileChooser(ValueCallback<Uri> filePathCallback) {
27
        mFilePathCallback = filePathCallback;
28
        Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
29
        intent.addCategory(Intent.CATEGORY_OPENABLE);
30
        intent.setType("*/*");
31
        mContext.startActivityForResult(Intent.createChooser(intent, "File Chooser"),
32
                REQUEST_FILE_PICKER);
33
    }
34
35
    // 3.0 + 调用这个方法
36
    public void openFileChooser(ValueCallback filePathCallback,
37
                                String acceptType) {
38
        mFilePathCallback = filePathCallback;
39
        Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
40
        intent.addCategory(Intent.CATEGORY_OPENABLE);
41
        intent.setType("*/*");
42
        mContext.startActivityForResult(Intent.createChooser(intent, "File Chooser"),
43
                REQUEST_FILE_PICKER);
44
    }
45
46
    //  / js上传文件的<input type="file" name="fileField" id="fileField" />事件捕获
47
    // Android > 4.1.1 调用这个方法
48
    public void openFileChooser(ValueCallback<Uri> filePathCallback,
49
                                String acceptType, String capture) {
50
        mFilePathCallback = filePathCallback;
51
        Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
52
        intent.addCategory(Intent.CATEGORY_OPENABLE);
53
        intent.setType("*/*");
54
        mContext.startActivityForResult(Intent.createChooser(intent, "File Chooser"),
55
                REQUEST_FILE_PICKER);
56
    }
57
58
    @Override
59
    public boolean onShowFileChooser(WebView webView,
60
                                     ValueCallback<Uri[]> filePathCallback,
61
                                     WebChromeClient.FileChooserParams fileChooserParams) {
62
        mFilePathCallbacks = filePathCallback;
63
        Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
64
        intent.addCategory(Intent.CATEGORY_OPENABLE);
65
        intent.setType("*/*");
66
        mContext.startActivityForResult(Intent.createChooser(intent, "File Chooser"),
67
                REQUEST_FILE_PICKER);
68
        return true;
69
    }
70
71
72
}

+ 4 - 0
app/src/main/res/values/arrays.xml

@ -13,6 +13,10 @@
13 13
        <item>"Android provides a rich application framework that allows you to build innovative apps and games for mobile devices in a Java language environment. The documents listed in the left navigation provide details about how to build apps using Android's various APIs."</item>
14 14
        <item>"test"</item>
15 15
    </string-array>
16
    <string-array name="photo">
17
        <item>拍照</item>
18
        <item>照片图库</item>
19
    </string-array>
16 20
17 21
    <string-array name="color_arr">
18 22
        <item>@color/lvse</item>

cdzApp - Gogs: Go Git Service

充电桩app代码

proguard-rules.pro 927B

    # Add project specific ProGuard rules here. # By default, the flags in this file are appended to flags specified # in /Users/jianxi/android/sdk/tools/proguard/proguard-android.txt # You can edit the include path and order by changing the proguardFiles # directive in build.gradle. # # For more details, see # http://developer.android.com/guide/developing/tools/proguard.html # Add any project specific keep options here: # If your project uses WebView with JS, uncomment the following # and specify the fully qualified class name to the JavaScript interface # class: #-keepclassmembers class fqcn.of.javascript.interface.for.webview { # public *; #} # Uncomment this to preserve the line number information for # debugging stack traces. #-keepattributes SourceFile,LineNumberTable # If you keep the line number information, uncomment this to # hide the original source file name. #-renamesourcefileattribute SourceFile