0

I have a website built using angularJS. Now I want to make an Android application using webview and some native code. So I want to get all redirect urls on click of anything in website, so that i can judge whether it to be loaded using angular or native. Since angular is doing internal routing I'm not able to get url using shouldoverrideUrlLoading from Andfroid.

Can someone please give a workaround. Or please help me in transferring data from angular to Android using javascriptInterface

Slashbin
  • 668
  • 5
  • 15

1 Answers1

0

You cannot transfer data directly from Angular to Android as angular is used at the client side of the application.

Why not use the same Rest API which if you are using and consuming in Angular Application. Use the same API in Android to get the data.

So, Basically the interaction of data should happen between your webserver API and Android.

If you just want to see the html page in android on click of that href link. Use WebView widget in android.

webView = (WebView) findViewById(R.id.webView1);
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl("http://www.google.com");

You can read more about it in developers doc..

http://developer.android.com/reference/android/webkit/WebView.html

Ritt
  • 3,181
  • 3
  • 22
  • 51
  • Thanks for the reply. All I need is to capture the click and get the href of that item. Sorry if I mislead by saying data. – Slashbin Apr 14 '16 at 12:19
  • okay, so use the same href in Android, use WebView widget. check my updated answer. – Ritt Apr 14 '16 at 12:29
  • I am using android webview for loading the site. If the site was having simple javascript I could have override the shouldOverrideUrlLoading method and get redirection url on click of any item in site. Since the site is built using angularJS, it will not reload on click of a link, instead it is doing internal routing and getting the new page. So I am not able to capture the href link since reload is not happening physically. http://stackoverflow.com/questions/4066438/android-webview-how-to-handle-redirects-in-app-instead-of-opening-a-browser - tells how to handle it in simple js – Slashbin Apr 14 '16 at 12:40
  • So i think passing the URL from angular to android before internal routing happens might solve this – Slashbin Apr 14 '16 at 12:47
  • okay so it's using internal routing right... Are you using stateProvider or urlProvider? if that internal routing is going to constant, then lets say you have page with some base url "abc.lan" and then on click of href in webapp, you angular url must be appending like "abc.lan/#/home". So, why not just use this constant url in your webView. – Ritt Apr 14 '16 at 18:12