I will describe first what we have now:
CMS - to populate database with drugs(meds) descriptions. Drug name as
textbox and CKEditor for description in HTML format.
WCF - export database to JSON
Android app- list of drugs and then webview to display drug description
in HTML format.
We need find solution to create inner links (i.e: drug name) in drug descriptions which will lead to mentioned drug description page.
Is there any way to achieve that with our current approach?
Even If I find a way how to create this feature in CMS (probably I will use hash tags to distinguish between external and internal links) still I have no idea how to get this functionality in Android app.
If this is risky or hard to add this feature to our current setup can you guys at least give me a idea how it should be build to apply this internal link feature.
I never did this before so I even have no idea where to start.
Thanks for any help.
Have your links in CMS have a custom href format - something like drug://drugid
and than in the android app (webview where you load the description, override shouldOverrideUrlLoading)
webView.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url.startsWith("drug://")) {
//this is where the click to that href will be intercepted
//extract the id from url and do whatever you want with it
return true; //disable the webview to load that url
}
return false;
}
});
For IOS devices override shouldStartLoadWithRequest:
- (BOOL)WebView:(UIWebView *)myWebView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
if([[request.URL absoluteString] hasPrefix:#"drug://"]) {
//this is where the click to that href will be intercepted
//extract the id from url and do whatever you want with it
return NO; //disable the webview to load that url
}
return YES;
}
Related
I have an acitivity with different fragments.in my home fragment i have a slider.i will be getting the dynamic url while clicking the slider image.i need to open another fragment with respect to the query parameter in the dynamic link.
My problem is i cannot convert this dynamic url to actual url.
For example the dymanic link is https://x97av.app.goo.gl/AbCD..I need to convert this link to https://abcd.com/lmno/a?id=2..
So i could easily fetch the id and move to respective screen.
you can use a hidden webview (not visible in UI) to load the dynamic URL, and use
mWebView.setWebViewClient(new WebViewClient() {
public void onPageFinished(WebView view, String url) {
// here you can use the actual url.
}
});
so, you can use the actual URL when the dynamic URL loaded.
I an using the WebView class to display tutorial in my apk. I like it as I can manage and update tutorial without making any changes in apk. I keep all tutorial html files in the specific folder on our website.
My question is there any events that will allow me to catch start navigation (when a user clicked on a link). I want to see on what link a user click in my tutorial and as long as a user navigate within the tutorial folder on our website he supposed to be navigating in WebView of my apk. However if there any link which lead outside of the tutorial folder then navigation to this link should be blocked and navigation should be passed to a browser.
I am not sure whether I explained it clearly. I am quite new to Android development. Please see below an example of my code in C# for Windows phone, I need to have the same in Android apk
/// <summary>
/// navigation in the application's browser goes as long as it is in the "stockscreenerapp" folder
/// if user goes out of this folder ("stockscreenerapp" cannot be found in the URL string) then
/// external default browser is called for further navigation
/// </summary>
private async void webBrowser1_NavigationStarting(WebView sender, WebViewNavigationStartingEventArgs args) {
if (null != args.Uri) {
string url = args.Uri.ToString();
int i = url.IndexOf("stockscreenerapp"); /* check whether "stockscreenerapp" is in the URL address */
if (i == -1) { args.Cancel = true; await Windows.System.Launcher.LaunchUriAsync(args.Uri); /*if it is not we call external browser and pass URL to it*/}
else { imgLoading.Visibility = Visibility.Visible; /* show loading image while page is loading */ }
}
}
Try using a WebViewClient and listening for onPageStarted. That way you can get the url of the clicked link, check if it's outside of your tutorial, and tell the WebView to stopLoading if it is.
In code, it might look something like this (warning, untested):
WebView webView = new WebView(context);
webView.setWebViewClient(new WebViewClient() {
#Override
public void onPageStarted (WebView view, String url, Bitmap favicon) {
if(Tutorial.doesNotContain(url))
view.stopLoading();
view.goBack();
}
});
I am working on an android project right now and have a question about how to do callbacks in different webviews. I used JSInterface for my project too. Here I have 2 webviews. One has an index page, anther is a overlay(still a html page though.) What I want to do is if any user clicks on some links on the overlay, it should fire a callback function which is written in the java file where the index page was connected to through JSInterface. It might sound confusing, but I have draw something to help make it clear!
Thanks!
You can use a custom URL scheme like myurl://function for your functionality links. Then write an event handler for the WebView's shouldOverrideUrlLoading event in which you decide how to process the URL: either instruct the webview to load it, or do some custom action.
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
if (url.startsWith("myurl://"))
{
// Parse further to extract function and do custom action
}
else
{
// Load the page via the webview
view.loadUrl(url);
}
return true;
}
I used startsWith to check the URL for this quick and dirty example, but you should consider using android.net.Uri.parse for parsing URLs.
This should allow you to call the Java function foo() without having to go through the first WebView.
If you want to go through the first webview, then you can call a function on the JSInterface like this (where webView1 is the first WebView retrieved through findViewById):
webView1.loadUrl("javascript:myjsinterface.myjsfunc();")
I have an application in which i have added a menu.
Clicking on this menu opens up a website.
There is a list of links(zip files) available on this website.
Clicking on a particular link should result in that zip file to be downloaded to the assets folder of my application.
I am able to load the website.
Code for this:
String url = "http://almondmendoza.com/android-applications/";
Intent k = new Intent(Intent.ACTION_VIEW);
k.setData(Uri.parse(url));
startActivity(k);
I am referring to the example given on this website
What i am curious to know is that whether it is possible to perform an action on click of a particular link available on website. If it is possible then how can i accomplish this task?
Use WebView to load webpage, you can recognize URL using following code
webView.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url){
webView.loadUrl(url);
// Here the String url hold 'Clicked URL'
return false;
}
});
I am trying to launch a websearch using data input from a user. The data is input through TextEdit boxes. Upon submission of the data, i would like my program to: 1) search for a specific webpage based on the user input 2)Find specific elements at the webpage 3) Display the webpage.
Here is an example:
User Input (in a non browser/webview page)
1) Store Name: Macey's 2)Zip Code: 77471
In the background my program will:
1) Find the Macey's website
2) Find the store nearest zip code 77471
3) Load the Web page for the store nearest zip code 77471
Obviously there is a lot of error handeling, exceptions, ect that would go along with this. For the sake of making this example "easy" lets pretend that 1) A the Macey's main page exists 2)A sperate page for the 77471 store exists. 3)There is a link to the 77471 store on the Macey's main page.
I have the code for getting the user input variables and i know how to launch the webview. What i dont know how to do is to search for the Macy's home page, then find the link i am looking for on the homepage and navigate to it. Loading the webview is not the problem. Find the data is.
Below is my current code. Right now i am setup so that the user will navigate to the webpage they are looking for but i would rather handle the searching for them, if it is possible.
public void InitializeWebView(){
portal = (WebView)findViewById(R.id.web_Portal);
WebSettings Settings = portal.getSettings();
Settings.setSavePassword(false);
Settings.setSaveFormData(false);
Settings.setJavaScriptEnabled(true);
Settings.setSupportZoom(true);
Settings.supportZoom();
portal.setWebViewClient(new WebViewClient(){
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
});
}
public void searchAndShow(String Store, String zip){
portal.loadUrl("http://www.google.com");
}
You can get search result in JSON format from google using their API. Here is a nice example in JAVA. Just don't use key parameter until you do not have a vlid key.