I use AdMob service to display advertisement in my android app.
I need to display advertisement using WebView instead of opening external web browser for it.
Overriding onLeaveApplication() method in AdListener doesn't help, external application is opened anyways after running method code.
Any solution?
you mean when you click on your ad it opens in a separate browser window? you would like it open inside the same webview?
then you just need to add a shouldoverrideurlloading. something like this:
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if( url.startsWith("http:") || url.startsWith("https:") ) {
return false;
}
// Otherwise allow the OS to handle it
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity( intent );
EDIT: sorry, this is only for the actual webview you are using in your app. since admob ads are displayed in their own little banner (which is essentially a webview too) it doesnt make sense to load that webpage into the banner. therefore a browser window has to pop up. may i ask why that is so important to you? I dont think it can be easily realized, meaning its not really possible.
Related
I have a hybrid application where I have a WebView which is implementing the shouldOverrideUrlLoading method (both the deprecated and the newest version). This should take over control before loading any external links or certain links within my domain. Without going into specifics, the code looks roughtly like this:
private WebView mWebView;
mWebView.setWebViewClient(new myWebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if(url.isExternal() || url.contains("#specialCase")) {
// Do actions
return true;
}
return super.shouldOverrideUrlLoading(view, url);
}
});
I have noticed that all external links work properly, however shouldOverrideUrlLoading is not being called at all when the link is within my domain, so there is no way for me to detect those cases where I want to take over control.
The android documentation states
Give the host application a chance to take over the control when a new
url is about to be loaded in the current WebView.
Does that new mean different domain? Is there anything I am missing or doing wrong? Any ideas on how to detect the user has clicked a link pointing to the same domain?
Thank you in advance.
Finally found the reason why shouldOverrideUrlLoading was never been called.
Apparently the method is only called when the actual loading is about to start. Our web application is a single-page application, hence even though the URL changes, no new page is loaded and shouldOverrideUrlLoading is not called.
Good day!
Guys, I have a problem and want your help.
Through a WebView, how do I get when clicked by the user, do not open the options of standard browsers (eg chrome and internet). I saw an app by clicking the link to the page opens normally however, as if open in a custom browser. I found it very interesting, and I wonder how this mechanics.
If anyone know how to create an app that perform the same procedure I am grateful.
For better doubt the APP is this:
https://play.google.com/store/apps/details?id=com.tachanfil.jornaisdobrasil&hl=pt-BR
You have to set up WebViewClient like
this.mWebView.setWebViewClient(new WebViewClient(){
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url){
view.loadUrl(url);
return true;
}
});
Then your app will display all links in your WebView instead of opening browser
Perhaps you are missing setting your client as the webview client - Refer to
http://developer.android.com/reference/android/webkit/WebView.html#setWebViewClient%28android.webkit.WebViewClient%29
I'm having what seems to be a pretty small issue in the Phonegap 1.3.0 application I am working on. It is for Android devices.
The problem is stemming from the ads I am trying to incorporate into my app. I am trying t use Leadbolt's no-SDK offer wall as well as their banner ads.
I am loading the offer wall within an iframe in my app, inside of a hidden DIV, and then displaying it when required - this part is working great.
The problem comes when I click on one of the links on the offer wall: instead of launching the clicked URL in a new External/Native browser, the link is being opened within the iframe. The same thing happens when someone clicks the banners, though these are integrated by inserting a in the location you want the ad to show rather than via an iframe. (Maybe the script injects an iframe, dunno, the end behavior is the same)
What I'm trying to do now is to implement a method in Java to catch any clicks, and open a new browser if the link is not relative/local - i.e. if it is prefixed by "http", "https", or "market" protocols
And here lies the real issue - the only experience I have with Java has been messing with Phoengap a bit :(
I have been reading and testing things all day, but finally I must resort to asking those of you who are more knowledgeable than I am in regards to Java programming.
Here is what I have been attempting so far:
package com.phonegap.my_great_app;
import android.os.Bundle;
import android.webkit.WebView;
import com.phonegap.*;
public class MyGreatApp extends DroidGap {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.loadUrl("file:///android_asset/www/index.html");
/* Intercept clicked links, and open external URLs in external browser */
public boolean shouldOverrideUrlLoading(DroidGap super, String url) {
if (url != null && url.startsWith("market://") || url.startsWith("http://") || url.startsWith("https://")) {
/* Open new WebView or external browser with URL */
/* Do it here */
Uri uri = Uri.parse(url);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
} else {
/* Do nothing, it's relative URL from my app */
return false;
}
}
}
}
I am sure this code is laughably wrong, but hopefully it can illustrate what I'm trying to achieve here. Truth be told, I have no idea if shouldOverrideUrlLoading() is even the right method to be calling for this problem!
I will be very grateful for any advice or code samples you can offer! Thanks :)
EDIT: Just to be clear - I cannot alter the iframe source code so javascript or changing the link targets is not an option due to XSS issues.
You can open external links in the default browser instead of opening inside your phonegap application. This can be done in two ways easily.
One is by using Phonegap medthod like this,
navigator.app.loadUrl('http://stackoverflow.com');
/*NOTE : In some phonegap versions it does not works*/
Another way is using jquery mobile, you can do like this,
YouTube Channel
Thats all.
I am curious how to load a webview when clicking on a mopub ad. By default the ad is opening a browser. There is very little documentation on this and I haven't been able to find any examples.
I instantiate the AdView class that I found in the mopub api as it seems like it should do what I want but to no avail. And I'm still not sure how to switch the ad click from browser to webview.
Also, getClickThroughUrl() returns null. Mopub is storing the url though because the page opens in a browser. So how do I properly retrieve the URL?
Here's my code:
mAdView.setAdUnitId(MOPUB_SALES_LIST_ID);
mAdView.loadAd();
mAdView.setOnAdLoadedListener(new OnAdLoadedListener() {
public void OnAdLoaded(MoPubView mpv) {
adPopupLayout.setVisibility(View.VISIBLE);
}
});
mAdView.setOnAdClickedListener(new OnAdClickedListener() {
#Override
public void OnAdClicked(MoPubView m) {
AdView adview = new AdView(getApplicationContext(), mAdView);
adview.loadUrl(m.getClickthroughUrl());
}
});
This is not very easy. You will have to make changes in the mopub SDK.
In the AdView class, you need to change the showBrowserForUrl() to load a webview instead of browser.
Since you have the URL that you need to go to. You could probably make yourself a WebView and call its load method passing along the URL, instead of calling load on the adview, which is probably just sending out the URL as an ACTION_VIEW intent, and the browser is set to listen for these when the content is a URL. If you install a 3rd party browser (firefox, opera, dolphin etc) and when you click the ad if you are given a list of options that includes all of the browsers installed you could verify that it is using the intent that way.
Hey everyone! Im pretty new to Android and I have a webView under 2 other widgets on the screen(Or w/e you call it). But when ever I navigate the webView, its changes to full screen and i cant see my other widgets. Ive looked all over Google but couldn't find anything, is there some way I can fix this?
Im using this code to navigate:
webView.loadUrl("http://www.example.com/");
Thank you.
webview.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url){
view.loadUrl(url);
return true;
}
});
when you do webView.loadUrl("www.example.com") or if there is a redirection when a hyperlink is clicked or something similar, the android device browser is started. I believe you are stuck with this. Try pasting the above code before you call the webView.loadUrl("www.example.com")
What we are essentially doing is asking the webview to load the url, instead of opening it in the device browser.