Search code examples
cordovacordova-pluginscordova-3cordova-4cordova-5.0.0

org.apache.cordova.CordovaWebView.removeView(View view) alternative for Cordova 4.0 and above?


I have a existing project where I had written phonegap plugin to add my own Android custom camera view or gallery view to CordovaWebView.

Upto Cordova 3.7 it is fine but from Cordova 4.0 , I am getting below error.

E/AndroidRuntime(25939): java.lang.NoSuchMethodError: No virtual method removeView(Landroid/view/View;)V in class Lorg/apache/cordova/CordovaWebView; or its super classes (declaration of 'org.apache.cordova.CordovaWebView' appears in /data/app/com.myworks.sample-2/base.apk)

After upgrading my existing project to Cordova 4.0, below code is showing compile errors.

mWebView.removeView(mGalleryView);// where mWebView is CordovaWebView and mGalleryView is my customized Android view.

is there any alternative for CordovaWebView.removeView(View view)? How can I add my custom native view to Html page through Android phonegap plugin.


Solution

  • getting mWebView's ViewGroup and adding/removing some views to it worked for me

     private ViewGroup mWebViewGroup = null;  
     mWebViewGroup = (ViewGroup) mWebView.getView().getParent();
     mWebViewGroup .addView(mGalleryView);
     // where mWebView is CordovaWebView and mGalleryView is my customized Android view