1

In my app, i am loading "http" url in the webview. This url is loaded correctly, but there are some internal url's loaded with the protocol "sheet://". While loading this url i get an error "protocol isn't supported". Can anyone please help how to fix this? How to load the url's with the protocol "sheet://" ?

PS: I am using shouldOverrideUrlLoading method to load the url.

This is the code I am using

 public boolean shouldOverrideUrlLoading(WebView view, String url) {
        if(url.contains("sheet://")){
          Intent url_intent = new Intent ( Intent.ACTION_VIEW,Uri.parse(url));
          url_intent.addCategory(Intent.CATEGORY_BROWSABLE);
          startActivity(url_intent);
          return false; 
        }else{
              view.loadUrl(url);
              return true; 
        }
 }

Thanks & Regards,

VijayRaj
  • 425
  • 1
  • 4
  • 22

3 Answers3

0

Perhaps host an PHP file, with an header?

<?php
header("Location: sheet://link_to_your_file.extention");
?>
Laurens
  • 121
  • 1
  • 12
0

Do you see the call to shouldOverrideUrlLoading come in for your sheet:// URL? That part of the code looks correct (assuming there is an app installed on your device that can handle sheet:// BROWSABLE intents). Or do you mean that the app launched from your app cannot load the sheet:// URL? What app is being launched to respond to the Intent?

One mistake you have is the call to loadUrl when sheet:// is not in the URL. In this case, please just return true. The URL load is already in progress, there is no need to start it again. Doing so infact creates a loop.

ksasq
  • 4,424
  • 2
  • 18
  • 10
  • I dont have any other app installed in my device.. I am trying to load sheet:// URL in my app..I removed the **Intent** part from the code and just returned false for sheet:// url, but I get "protocol isn't supported" – VijayRaj Mar 07 '14 at 05:59
  • That's expected then. If there isn't any thing on the device to handle your custom scheme then how can it be supported? What is it you expect to be loaded for sheet URLs? Do you want to use the shouldInterceptRequest API instead which allows you to provide your own InputStream in response to a request? – ksasq Mar 07 '14 at 07:14
  • I got this working :) I want to know how to get a return value when I load a javascript function inside webview? – VijayRaj Mar 27 '14 at 06:36
  • Glad to hear it's working, what was the solution in the end? For JavaScript, there isn't a way to do it synchronously. On Android 4.4 you can use WebView.evaluateJavascript and pass in a callback that will run with the result, prior to 4.4 you will need a combination of loadUrl(javascript:) and addJavaScriptInterface to receive the result. – ksasq Mar 27 '14 at 08:47
  • sheet protocol url was not meant to be loaded..I was trying to load it and hence got that error....Regarding javascript, if I use addJavaScriptInterface, I have to change the code in my js file....Since we are using same js code for ios, is there any other way to get response ? – VijayRaj Mar 27 '14 at 09:05
  • the only other thing I can think of would be to have the javascript you call in loadUrl call back to your app with the result via an alert() dialog (you can intercept alert dialogs with WebChromeClient.onJsAlert). WebView.loadUrl(javascript:alert(foo());) – ksasq Mar 27 '14 at 09:18
  • I tried this...but the function in alert is not getting executed :( This is how I am using it `webview.loadUrl("javascript:alert(functionToExecute(arg0,arg1));")` – VijayRaj Mar 27 '14 at 10:22
  • When are you doing that? Is the page fully loaded so that functionToExecute() is defined? Any messages in logcat? If you just do alert("test") does it go through to your app? – ksasq Mar 28 '14 at 08:13
0

You have to register an activity with an intent-filter that matches that protocol in your AndroidManifest.xml

Fernando Gallego
  • 4,064
  • 31
  • 50