Przeglądaj źródła

1.修改Android Apex CRM图片选择及上传。

Pen Li 7 lat temu
rodzic
commit
aa8d579789

+ 35 - 2
ApexDrivers/apexcrm/src/main/java/com/usai/apex/apexcrm/MainActivity.java

@@ -371,7 +371,7 @@ public class MainActivity extends AppCompatActivity implements RAWebView.WebView
 
     private void setWebImageForPath(String path) {
         if (path != null) {
-//            String imgBase64 = FileManager.base64StringFromFile(path);
+            String imgBase64 = FileManager.base64StringFromFile(path);
 //            setWebImageWithBase64(imgBase64);
 
             /**
@@ -379,7 +379,10 @@ public class MainActivity extends AppCompatActivity implements RAWebView.WebView
              * 如果直接写file://xxxx 那么webview不会加载
              * 建议写为http://local/file://
              * */
-            evaluateCurrentAction(String.format("%s%s",RALocalFileScheme,path));
+//            evaluateCurrentAction(String.format("%s%s",RALocalFileScheme,path));
+
+            String base64 = String.format("data:image/jpg;base64,%s",imgBase64);
+            evaluateCurrentAction(base64);
         }
     }
 
@@ -1060,8 +1063,38 @@ public class MainActivity extends AppCompatActivity implements RAWebView.WebView
            });
 
         }
+
+        @Override
+        public String FileBase64(String msg) {
+
+            try {
+                JSONObject json = new JSONObject(msg);
+
+                String path = json.getString("path");
+
+                // http://local/file:///data/user_de/0/com.usai.apex.apexcrm/cache/20190128_150550
+//                path = "http://local/file:///data/user_de/0/com.usai.apex.apexcrm/cache/20190128_150550";
+                if (path != null) {
+                    path = path.replace(RALocalFileScheme, "");
+                }
+
+                String imageWithBase64 = base64(path);
+                String base64 = String.format("data:image/jpg;base64,%s",imageWithBase64);
+
+                return base64;
+
+            } catch (JSONException e) {
+                e.printStackTrace();
+            }
+            return null;
+        }
     };
 
+    private static String base64(String path) {
+
+        return FileManager.base64StringFromFile(path);
+    }
+
     // region Loac Callback
 
     private boolean initialize = false; // 首页加载完成

+ 13 - 1
ApexDrivers/apexcrm/src/main/java/com/usai/apex/apexcrm/RAJSInterface.java

@@ -1,6 +1,5 @@
 package com.usai.apex.apexcrm;
 
-
 import com.usai.redant.rautils.utils.RAUtil;
 
 import org.json.JSONObject;
@@ -23,6 +22,7 @@ public class RAJSInterface extends Object {
         void SelectContact(String msg);
         void RequestAppVersion(String msg);
         void CleanCache(String msg);
+        String FileBase64(String msg);
     }
 
     private RAJSInterfaceDelegate delegate;
@@ -30,6 +30,7 @@ public class RAJSInterface extends Object {
         this.delegate = delegate;
     }
 
+    // region WebKit
     @android.webkit.JavascriptInterface
     public void CamScan(String msg) {
 
@@ -149,6 +150,17 @@ public class RAJSInterface extends Object {
         }
     }
 
+    @android.webkit.JavascriptInterface
+    public String base64(String msg) {
+
+        if (delegate != null) {
+            return delegate.FileBase64(msg);
+        }
+        return null;
+    }
+
+    // endregion
+
     private static boolean jsonValueIsNull(JSONObject json, String key) {
 
         if (json != null && key != null && json.has(key)) {

+ 4 - 0
ApexDrivers/apexcrm/src/main/java/com/usai/apex/apexcrm/RAWebView.java

@@ -129,6 +129,10 @@ public class RAWebView extends RelativeLayout {
 //            webSettings.setAppCacheEnabled(false);
 //            webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);
 
+            // debug
+            // chrome://inspect/#devices
+            WebView.setWebContentsDebuggingEnabled(true);
+
             hackWebJSMethod();
             hackWebURL();
         }