@Override public void onActivityResult(int requestCode, int resultCode, Intent intent) { if (requestCode == REQUEST_FILE_PICKER) { if (mFilePathCallback4 != null) { Uri result = intent == null || resultCode != Activity.RESULT_OK ? null : intent.getData(); if (result != null) { String path = MediaUtility.getPath(getActivity(), result); Uri uri = Uri.fromFile(new File(path)); mFilePathCallback4.onReceiveValue(uri); } else { mFilePathCallback4.onReceiveValue(null); } } if (mFilePathCallback5 != null) { Uri result = intent == null || resultCode != Activity.RESULT_OK ? null : intent.getData(); if (result != null) { String path = MediaUtility.getPath(getActivity(), result); Uri uri = Uri.fromFile(new File(path)); mFilePathCallback5.onReceiveValue(new Uri[] {uri}); } else { mFilePathCallback5.onReceiveValue(null); } } mFilePathCallback4 = null; mFilePathCallback5 = null; } }
/** * Called when an activity you launched exits, giving you the requestCode you started it with, the * resultCode it returned, and any additional data from it. * * @param requestCode The request code originally supplied to startActivityForResult(), allowing * you to identify who this result came from. * @param resultCode The integer result code returned by the child activity through its * setResult(). * @param data An Intent, which can return result data to the caller (various data can be attached * to Intent "extras"). */ @Override protected void onActivityResult(int requestCode, int resultCode, Intent intent) { LOG.d(TAG, "Incoming Result"); super.onActivityResult(requestCode, resultCode, intent); Log.d(TAG, "Request code = " + requestCode); if (appView != null && requestCode == CordovaChromeClient.FILECHOOSER_RESULTCODE) { ValueCallback<Uri> mUploadMessage = this.appView.getWebChromeClient().getValueCallback(); Log.d(TAG, "did we get here?"); if (null == mUploadMessage) return; Uri result = intent == null || resultCode != Activity.RESULT_OK ? null : intent.getData(); Log.d(TAG, "result = " + result); mUploadMessage.onReceiveValue(result); mUploadMessage = null; } CordovaPlugin callback = this.activityResultCallback; if (callback == null && initCallbackClass != null) { // The application was restarted, but had defined an initial callback // before being shut down. this.activityResultCallback = appView.pluginManager.getPlugin(initCallbackClass); callback = this.activityResultCallback; } if (callback != null) { LOG.d(TAG, "We have a callback to send this result to"); callback.onActivityResult(requestCode, resultCode, intent); } }
@Override public void showFileChooser( final ValueCallback<String[]> uploadFileCallback, final AwContentsClient.FileChooserParams fileChooserParams) { if (mWebChromeClient == null) { uploadFileCallback.onReceiveValue(null); return; } TraceEvent.begin(); FileChooserParamsAdapter adapter = new FileChooserParamsAdapter(fileChooserParams, mWebView.getContext()); if (TRACE) Log.d(TAG, "showFileChooser"); ValueCallback<Uri[]> callbackAdapter = new ValueCallback<Uri[]>() { private boolean mCompleted; @Override public void onReceiveValue(Uri[] uriList) { if (mCompleted) { throw new IllegalStateException("showFileChooser result was already called"); } mCompleted = true; String s[] = null; if (uriList != null) { s = new String[uriList.length]; for (int i = 0; i < uriList.length; i++) { s[i] = uriList[i].toString(); } } uploadFileCallback.onReceiveValue(s); } }; if (mWebChromeClient.onShowFileChooser(mWebView, callbackAdapter, adapter)) { return; } if (mWebView.getContext().getApplicationInfo().targetSdkVersion > Build.VERSION_CODES.KITKAT) { uploadFileCallback.onReceiveValue(null); return; } ValueCallback<Uri> innerCallback = new ValueCallback<Uri>() { private boolean mCompleted; @Override public void onReceiveValue(Uri uri) { if (mCompleted) { throw new IllegalStateException("showFileChooser result was already called"); } mCompleted = true; uploadFileCallback.onReceiveValue(uri == null ? null : new String[] {uri.toString()}); } }; if (TRACE) Log.d(TAG, "openFileChooser"); mWebChromeClient.openFileChooser( innerCallback, fileChooserParams.acceptTypes, fileChooserParams.capture ? "*" : ""); TraceEvent.end(); }
public void openFileChooser( ValueCallback<Uri> paramValueCallback, String paramString1, String paramString2) { mUploadMessage = paramValueCallback; paramValueCallback = new Intent("android.intent.action.GET_CONTENT"); paramValueCallback.addCategory("android.intent.category.OPENABLE"); paramValueCallback.setType("*/*"); cordova .getActivity() .startActivityForResult(Intent.createChooser(paramValueCallback, "File Browser"), 5173); }
@Override protected final void onActivityResult(int requestCode, int resultCode, Intent data) { if (F_OAUTH_CODE == requestCode) { if (null != data) { int result = data.getIntExtra("result", 0); if (0 == result) { exitBrowser(); return; } String authorizeID = data.getStringExtra("authorizeID"); uexOnAuthorize(authorizeID); } return; } else if (requestCode == FILECHOOSER_RESULTCODE) { if (null == mUploadMessage) return; Uri result = data == null || resultCode != RESULT_OK ? null : data.getData(); mUploadMessage.onReceiveValue(result); mUploadMessage = null; } if (mCallbackRuning && null != mActivityCallback) { mActivityCallback.onActivityResult(requestCode, resultCode, data); mCallbackRuning = false; mActivityCallback = null; } }
/** * 浏览器请求文件. * * <p>浏览器请求文件资源上传附件,宿主APP 此时可以打开系统文件管理器或者第三方文件管理,或者一个特定的 Intent 对象. browserCallback回调是阻塞式的, * 所以必须回调, 如果未处理也必须回调 null 值. 请求文件, 可以是系统文件选择器,也可以是开发自己实现的文件选择器. * * @param browserCallback 参数回传回调方法. * @param fileManagerIntent */ @Override public void onBrowserFileRequest(ValueCallback browserCallback, Intent fileManagerIntent) { Toast.makeText(this, "文件", Toast.LENGTH_LONG).show(); // 如果无参数也必须回调.否则网页会阻塞 browserCallback.onReceiveValue(null); startActivity(fileManagerIntent); }
/** * 浏览器请求相机拍照用于上传附件. * * @param browserCallback 参数回传回调方法,该回调是阻塞式的, 所以必须回调, 如果未处理也必须回调 null 值. * @param galleryIntent */ @Override public void onBrowserCameraRequest(ValueCallback browserCallback, Intent galleryIntent) { Toast.makeText(this, "拍照", Toast.LENGTH_LONG).show(); // 如果无参数也必须回调.否则网页会阻塞 browserCallback.onReceiveValue(null); startActivity(galleryIntent); }
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { case INPUT_FILE_REQUEST_CODE: // 5.0以上系统处理 if (mFilePathCallback == null) { super.onActivityResult(requestCode, resultCode, data); return; } Uri[] results = null; // Check that the response is a good one if (resultCode == Activity.RESULT_OK) { if (data == null) { // If there is not data, then we may have taken a photo if (mCameraPhotoPath != null) { results = new Uri[] {Uri.parse(mCameraPhotoPath)}; } } else { String dataString = data.getDataString(); if (dataString != null) { results = new Uri[] {Uri.parse(dataString)}; } } } mFilePathCallback.onReceiveValue(results); mFilePathCallback = null; break; case FILECHOOSER_RESULTCODE: // 低版本处理 if (null == mUploadMessage) { super.onActivityResult(requestCode, resultCode, data); return; } ; Uri result = data == null || resultCode != Activity.RESULT_OK ? null : data.getData(); if (result == null && data == null && resultCode == Activity.RESULT_OK) { File cameraFile = new File(mCameraPhotoPath); if (cameraFile.exists()) { result = Uri.fromFile(cameraFile); sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, result)); } } mUploadMessage.onReceiveValue(result); mUploadMessage = null; break; } super.onActivityResult(requestCode, resultCode, data); }
@Override protected void onActivityResult(int requestCode, int resultCode, Intent intent) { if (requestCode == FILECHOOSER_RESULTCODE) { if (null == mUploadMessage) return; Uri result = intent == null || resultCode != RESULT_OK ? null : intent.getData(); mUploadMessage.onReceiveValue(result); mUploadMessage = null; } }
@Override protected void onActivityResult(int requestCode, int resultCode, Intent intent) { if (requestCode == FILECHOOSER_RESULTCODE) { if (null == mUploadMessage) return; Uri result = intent == null || resultCode != RESULT_OK ? null : intent.getData(); mUploadMessage.onReceiveValue(result); mUploadMessage = null; } else if (requestCode == FILECHOOSER_RESULTCODE_FOR_ANDROID_5) { if (null == mUploadMessageForAndroid5) return; Uri result = (intent == null || resultCode != RESULT_OK) ? null : intent.getData(); if (result != null) { mUploadMessageForAndroid5.onReceiveValue(new Uri[] {result}); } else { mUploadMessageForAndroid5.onReceiveValue(new Uri[] {}); } mUploadMessageForAndroid5 = null; } }
@Override protected void onActivityResult(int requestCode, int resultCode, Intent intent) { if (requestCode == FILECHOOSER_RESULTCODE) { // found this from StackOverflow if (null == mUploadMessage) return; Uri result = intent == null || resultCode != RESULT_OK ? null : intent.getData(); mUploadMessage.onReceiveValue(result); mUploadMessage = null; } else { // -----------I wrote this code below this line---------------------------------- jpegData = intent.getExtras().getByteArray("image"); Bitmap img = BitmapFactory.decodeByteArray(jpegData, 0, jpegData.length); Drawable d = new BitmapDrawable(img); profilePicture.setBackground(d); } }
@Override /** old 根据requestCode处理上传 */ protected void onActivityResult(int requestCode, int resultCode, Intent intent) { if (requestCode == Constants.FILECHOOSER_RESULTCODE) { if (null == mUploadMessage) return; Uri result = intent == null || resultCode != RESULT_OK ? null : intent.getData(); mUploadMessage.onReceiveValue(result); mUploadMessage = null; } else { super.onActivityResult(requestCode, resultCode, intent); PluginInterface callback = this.activityResultCallback; if (callback != null) { callback.onActivityResult(requestCode, resultCode, intent); } } }
/** * Notify the host application that an SSL error occurred while loading a resource. The host * application must call either handler.cancel() or handler.proceed(). Note that the decision may * be retained for use in response to future SSL errors. The default behavior is to cancel the * load. * * @param view The WebView that is initiating the callback. * @param handler An SslErrorHandler object that will handle the user's response. * @param error The SSL error object. */ @TargetApi(8) @Override public void onReceivedSslError(XWalkView view, ValueCallback<Boolean> callback, SslError error) { final String packageName = appView.cordova.getActivity().getPackageName(); final PackageManager pm = appView.cordova.getActivity().getPackageManager(); ApplicationInfo appInfo; try { appInfo = pm.getApplicationInfo(packageName, PackageManager.GET_META_DATA); if ((appInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0) { // debug = true callback.onReceiveValue(true); return; } else { // debug = false super.onReceivedSslError(view, callback, error); } } catch (NameNotFoundException e) { // When it doubt, lock it out! super.onReceivedSslError(view, callback, error); } }
@Override public void onReceivedSslError(ValueCallback<Boolean> callback, SslError error) { callback.onReceiveValue(mAllowSslError); mOnReceivedSslErrorHelper.notifyCalled(); }
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { Cursor cursor = null; try { if (requestCode == GloableUtils.RESULT_PICK_PHOTO_NORMAL && data != null) { String filePath = null; Uri uri = data.getData(); if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) { filePath = BitmapUtils.getPath(uri); } else { String[] cloums = {MediaStore.Images.Media.DATA}; cursor = getContentResolver().query(uri, cloums, null, null, null); cursor.moveToFirst(); filePath = cursor.getString(0); } BitmapUtils.cropImageUri(filePath); } } finally { if (cursor != null) cursor.close(); System.gc(); } if (requestCode == GloableUtils.CROP_A_PICTURE) { Bitmap bitmap = null; try { String path = "/mnt/sdcard/temp.jpg"; bitmap = BitmapUtils.compressPictureFromFile(path); String pictureBytes = ParseUtils.getBase64FromBitmap(bitmap); pictureBytes = "data:image/png;base64," + pictureBytes; webView.loadUrl("javascript:G_jsCallBack.selectHeadPic_callback('" + pictureBytes + "')"); } catch (Exception e) { ExUtil.e(e); } finally { BitmapUtils.recyleBitmap(bitmap); } } if (requestCode == GloableUtils.CHOOSE_PICTURE_ONLY && data != null) { Bitmap bitmap = null; try { Uri uri = data.getData(); String storagePath = BitmapUtils.getPath(uri); getImageBase(storagePath); // base = "data:image/png;base64," + base; // Log.i("if", "打印bsdfs" + base); // 选择无裁剪图片成功后上传base64字符串 // TODO // webView.loadUrl("javascript:G_jsCallBack.selectPic_callback('" + base // + "')"); } finally { BitmapUtils.recyleBitmap(bitmap); } } if (requestCode == GloableUtils.FILECHOOSER_RESULTCODE) { if (null == myUploadMsg) return; Uri result = data == null || resultCode != RESULT_OK ? null : data.getData(); myUploadMsg.onReceiveValue(result); myUploadMsg = null; } }