android webview - Access-Control-Allow-Origin -


xmlhttprequest cannot load  - origin website... not allowed access-control-allow-origin.:1 

i cannot load video inside webview.

this log:

03-18 12:31:25.324: e/web console(7074): xmlhttprequest cannot load http://3.stream.site.com/mycams/en/watch/test?gravitycookieid=ba6605bdb69d29163fb4d97594fc8b169&mycams_session=6a2294654ccadg6854c21edc3e6598cfa&ispromo=&ishls=. origin http://m.site1.com not allowed access-control-allow-origin.:1 03-18 12:31:25.324: e/web console(7074): ajax handler error: url: http://3.stream.site2.com/mycams/en/watch/test?gravitycookieid=ba6605bdb69d29163fb4d97594fc8b169&mycams_session=6a2294654ccadg6854c21edc3e6598cfa&ispromo=&ishls= || status:0|| statustext: error|| responsetext: :4620 

even using:

    if (android.os.build.version.sdk_int >= android.os.build.version_codes.jelly_bean) {         websettings.setallowuniversalaccessfromfileurls(true);         websettings.setallowfileaccessfromfileurls(true);         websettings.setallowcontentaccess(true);         websettings.setappcacheenabled(true);         }  

what's solution ?

i've solved java.lang.reflect.method:

1- create new class extends webview, in case newwebview:

newwebview.class

package my.pkg.name;  import java.lang.reflect.method; import android.annotation.suppresslint; import android.content.context; import android.util.log; import android.webkit.webview;  @suppresslint("instantiatable") public class newwebview extends webview {      @suppresslint("instantiatable")     public newwebview(context context)     {         super(context);         // todo auto-generated constructor stub     }      public void enablecrossdomain()     {         try         {             field field = webview.class.getdeclaredfield("mwebviewcore");             field.setaccessible(true);             object webviewcore=field.get(this);             method method = webviewcore.getclass().getdeclaredmethod("nativeregisterurlschemeaslocal", string.class);             method.setaccessible(true);               method.invoke(webviewcore, "http");             method.invoke(webviewcore, "https");         }         catch(exception e)         {             log.d("wokao","enablecrossdomain error");             e.printstacktrace();         }     }      //for android 4.1+      public void enablecrossdomain41()     {         try         {             field webviewclassic_field = webview.class.getdeclaredfield("mprovider");             webviewclassic_field.setaccessible(true);             object webviewclassic=webviewclassic_field.get(this);             field webviewcore_field = webviewclassic.getclass().getdeclaredfield("mwebviewcore");             webviewcore_field.setaccessible(true);             object mwebviewcore=webviewcore_field.get(webviewclassic);             field nativeclass_field = webviewclassic.getclass().getdeclaredfield("mnativeclass");             nativeclass_field.setaccessible(true);             object mnativeclass=nativeclass_field.get(webviewclassic);              method method = mwebviewcore.getclass().getdeclaredmethod("nativeregisterurlschemeaslocal",new class[] {int.class,string.class});             method.setaccessible(true);             method.invoke(mwebviewcore,mnativeclass, "http");             method.invoke(mwebviewcore,mnativeclass, "https");         }         catch(exception e)         {             log.d("wokao","enablecrossdomain error");             e.printstacktrace();         }     } 

2 - use new class newwebview inside main activity , this:

main.class

public class main extends activity {     private newwebview webview;      public void oncreate(bundle savedinstancestate)     {         super.oncreate(savedinstancestate);          webview = new newwebview(this);         websettings websettings = webview.getsettings();          if (android.os.build.version.sdk_int >= android.os.build.version_codes.jelly_bean)         {             webview.enablecrossdomain41();              websettings.setallowuniversalaccessfromfileurls(true);                 websettings.setallowfileaccessfromfileurls(true);          }         else         {             webview.enablecrossdomain();             }           //rest of code here     } } 

source: http://blog.sina.com.cn/s/blog_723eed4f01018r9w.html (chinese)


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

How to get multiresult with multicondition in Sql Server -