|
|
@@ -1,6 +1,7 @@
|
|
|
package com.modular.apputils.activity;
|
|
|
|
|
|
import android.annotation.SuppressLint;
|
|
|
+import android.annotation.TargetApi;
|
|
|
import android.content.ActivityNotFoundException;
|
|
|
import android.content.Intent;
|
|
|
import android.net.Uri;
|
|
|
@@ -10,6 +11,7 @@ import android.os.Environment;
|
|
|
import android.text.TextUtils;
|
|
|
import android.view.KeyEvent;
|
|
|
import android.widget.RelativeLayout;
|
|
|
+import android.widget.Toast;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.common.LogUtil;
|
|
|
@@ -26,6 +28,8 @@ import com.modular.apputils.R;
|
|
|
import com.tencent.smtt.sdk.CookieManager;
|
|
|
import com.tencent.smtt.sdk.TbsReaderView;
|
|
|
import com.tencent.smtt.sdk.TbsReaderView.ReaderCallback;
|
|
|
+import com.tencent.smtt.sdk.ValueCallback;
|
|
|
+import com.tencent.smtt.sdk.WebChromeClient;
|
|
|
import com.tencent.smtt.sdk.WebSettings;
|
|
|
import com.tencent.smtt.sdk.WebView;
|
|
|
import com.tencent.smtt.sdk.WebViewClient;
|
|
|
@@ -100,6 +104,7 @@ public class SimpleWebActivity extends OABaseActivity implements ReaderCallback
|
|
|
}
|
|
|
});
|
|
|
LogUtil.d(TAG, "url=" + url);
|
|
|
+ webView.setWebChromeClient(mWebChromeClient);
|
|
|
webView.loadUrl(url);
|
|
|
}
|
|
|
|
|
|
@@ -219,4 +224,76 @@ public class SimpleWebActivity extends OABaseActivity implements ReaderCallback
|
|
|
}
|
|
|
return ssfFactory;
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ //由于优软商城无法兼容弹出窗体,现在添加
|
|
|
+ private WebChromeClient mWebChromeClient = new WebChromeClient() {
|
|
|
+
|
|
|
+
|
|
|
+ // For 3.0+ Devices (Start)
|
|
|
+ // onActivityResult attached before constructor
|
|
|
+ protected void openFileChooser(ValueCallback uploadMsg, String acceptType) {
|
|
|
+ mUploadMessage = uploadMsg;
|
|
|
+ Intent i = new Intent(Intent.ACTION_GET_CONTENT);
|
|
|
+ i.addCategory(Intent.CATEGORY_OPENABLE);
|
|
|
+ i.setType("image/*");
|
|
|
+ startActivityForResult(Intent.createChooser(i, "File Browser"), FILECHOOSER_RESULTCODE);
|
|
|
+ }
|
|
|
+
|
|
|
+ // For Lollipop 5.0+ Devices
|
|
|
+ @TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
|
|
+ public boolean onShowFileChooser(WebView mWebView, ValueCallback<Uri[]> filePathCallback, WebChromeClient.FileChooserParams fileChooserParams) {
|
|
|
+ if (uploadMessage != null) {
|
|
|
+ uploadMessage.onReceiveValue(null);
|
|
|
+ uploadMessage = null;
|
|
|
+ }
|
|
|
+
|
|
|
+ uploadMessage = filePathCallback;
|
|
|
+
|
|
|
+ Intent intent = fileChooserParams.createIntent();
|
|
|
+ try {
|
|
|
+ startActivityForResult(intent, REQUEST_SELECT_FILE);
|
|
|
+ } catch (ActivityNotFoundException e) {
|
|
|
+ uploadMessage = null;
|
|
|
+ Toast.makeText(getBaseContext(), "Cannot Open File Chooser", Toast.LENGTH_LONG).show();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void openFileChooser(ValueCallback<Uri> uploadMsg) {
|
|
|
+ mUploadMessage = uploadMsg;
|
|
|
+ Intent i = new Intent(Intent.ACTION_GET_CONTENT);
|
|
|
+ i.addCategory(Intent.CATEGORY_OPENABLE);
|
|
|
+ i.setType("image/*");
|
|
|
+ startActivityForResult(Intent.createChooser(i, "File Chooser"), FILECHOOSER_RESULTCODE);
|
|
|
+ }
|
|
|
+ };
|
|
|
+ private ValueCallback<Uri> mUploadMessage;
|
|
|
+ public ValueCallback<Uri[]> uploadMessage;
|
|
|
+ public static final int REQUEST_SELECT_FILE = 100;
|
|
|
+ private final static int FILECHOOSER_RESULTCODE = 2;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onActivityResult(int requestCode, int resultCode, Intent intent) {
|
|
|
+
|
|
|
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
|
|
+ if (requestCode == REQUEST_SELECT_FILE) {
|
|
|
+ if (uploadMessage == null)
|
|
|
+ return;
|
|
|
+ uploadMessage.onReceiveValue(WebChromeClient.FileChooserParams.parseResult(resultCode, intent));
|
|
|
+ uploadMessage = null;
|
|
|
+ }
|
|
|
+ } else if (requestCode == FILECHOOSER_RESULTCODE) {
|
|
|
+ if (null == mUploadMessage)
|
|
|
+ return;
|
|
|
+ // Use MainActivity.RESULT_OK if you're implementing WebView inside Fragment
|
|
|
+ // Use RESULT_OK only if you're implementing WebView inside an Activity
|
|
|
+ Uri result = intent == null || resultCode != RESULT_OK ? null : intent.getData();
|
|
|
+ mUploadMessage.onReceiveValue(result);
|
|
|
+ mUploadMessage = null;
|
|
|
+ } else
|
|
|
+ Toast.makeText(getBaseContext(), "Failed to Upload Image", Toast.LENGTH_LONG).show();
|
|
|
+ }
|
|
|
+
|
|
|
}
|