You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by GitBox <gi...@apache.org> on 2019/05/30 14:14:32 UTC

[GitHub] [cordova-plugin-inappbrowser] robertolanza93 commented on issue #328: Can not open camera when I click input type="file" on Android devices

robertolanza93 commented on issue #328: Can not open camera when I click input type="file" on Android devices
URL: https://github.com/apache/cordova-plugin-inappbrowser/issues/328#issuecomment-497344614
 
 
   > Please, install cordova-plugin-inappbrowser@3.0.0 in you ionic app and replace the content file node_modules\cordova-plugin-inappbrowser\src\android\InAppBrowser.java with below code. Try app and give feeback, ok?
   > 
   > ```
   > /*
   >        Licensed to the Apache Software Foundation (ASF) under one
   >        or more contributor license agreements.  See the NOTICE file
   >        distributed with this work for additional information
   >        regarding copyright ownership.  The ASF licenses this file
   >        to you under the Apache License, Version 2.0 (the
   >        "License"); you may not use this file except in compliance
   >        with the License.  You may obtain a copy of the License at
   > 
   >          http://www.apache.org/licenses/LICENSE-2.0
   > 
   >        Unless required by applicable law or agreed to in writing,
   >        software distributed under the License is distributed on an
   >        "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
   >        KIND, either express or implied.  See the License for the
   >        specific language governing permissions and limitations
   >        under the License.
   > */
   > package org.apache.cordova.inappbrowser;
   > 
   > import android.Manifest;
   > import android.annotation.SuppressLint;
   > import android.app.Activity;
   > import android.content.Context;
   > import android.content.Intent;
   > import android.content.pm.PackageManager;
   > import android.os.Environment;
   > import android.provider.Browser;
   > import android.content.res.Resources;
   > import android.graphics.Bitmap;
   > import android.graphics.drawable.Drawable;
   > import android.graphics.PorterDuff;
   > import android.graphics.PorterDuffColorFilter;
   > import android.graphics.Color;
   > import android.net.Uri;
   > import android.os.Build;
   >.
   >.
   >.
   >.
   >.
   >.
   >.
   >.
   >.
   >.
   >.
   >.
   >                 // WebView
   >                 inAppWebView = new WebView(cordova.getActivity());
   >                 inAppWebView.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
   >                 inAppWebView.setId(Integer.valueOf(6));
   >                 // File Chooser Implemented ChromeClient
   >                 inAppWebView.setWebChromeClient(new InAppChromeClient(thatWebView) {
   >                     // For Android 5.0+
   >                     public boolean onShowFileChooser (WebView webView, ValueCallback<Uri[]> filePathCallback, WebChromeClient.FileChooserParams fileChooserParams)
   >                     {
   >                         if(Build.VERSION.SDK_INT >=23 && (cordova.getActivity().checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED || cordova.getActivity().checkSelfPermission(Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED)) {
   >                             cordova.getActivity().requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.CAMERA}, 1);
   >                         }
   > 
   >                         LOG.d(LOG_TAG, "File Chooser 5.0+");
   > 
   >                         // If callback exists, finish it.
   >                         if(mUploadCallbackLollipop != null) {
   >                             mUploadCallbackLollipop.onReceiveValue(null);
   >                         }
   >                         mUploadCallbackLollipop = filePathCallback;
   > 
   >                         Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
   > 
   >             }
   > 
   >             // By default handle 401 like we'd normally do!
   >             super.onReceivedHttpAuthRequest(view, handler, host, realm);
   >         }
   >     }
   > }
   > ```
   
   This worked for me.
   After you have copied the file, you have to remove the android platform and add it again, then build and try :)
   
   
   thanks a lot @gilbertogwa !

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org