android - Cannot click on interstitial ad in WebView fragment -
i have made advancewebview application.
in have made function show interstitialad in "fragmentactivity", means whenever download webview ad show isn't clickable.
i think ad showing behind fragment or or maybe other issue. , when vedio ads showen, countdown of ad doesn't woprking.
i can see ad isn't clickable , if click on part of ad, logcat
showing => "i/hwsecimmhelper: msecurityinputmethodservice null"
here part of code:
webfragmentactivy:
public class webfragment extends fragment implements advancedwebview.listener, swiperefreshlayout.onrefreshlistener{ //layouts public framelayout rl; public advancedwebview browser; public swiperefreshlayout swipelayout; public progressbar progressbar; //webview clients public webtoappchromeclient chromeclient; public webtoappwebclient webclient; //webview session public string mainurl = null; static string url = "url"; public int firstload = 0; //keep track of interstitials show private int interstitialcount = -1; public webfragment() { // required empty public constructor } public static webfragment newinstance(string url) { webfragment fragment = new webfragment(); bundle args = new bundle(); args.putstring(url, url); fragment.setarguments(args); return fragment; } public void setbaseurl(string url){ this.mainurl = url; browser.loadurl(mainurl); } @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); if (getarguments() != null && mainurl == null) { mainurl = getarguments().getstring(url); firstload = 0; } } @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { rl = (framelayout) inflater.inflate(r.layout.fragment_observable_web_view, container, false); progressbar = (progressbar) rl.findviewbyid(r.id.progressbar); browser = (advancedwebview) rl.findviewbyid(r.id.scrollable); swipelayout = (swiperefreshlayout) rl.findviewbyid(r.id.swipe_container); return rl; } @override public void onactivitycreated(bundle savedinstancestate) { super.onactivitycreated(savedinstancestate); if (config.pull_to_refresh) swipelayout.setonrefreshlistener(this); else swipelayout.setenabled(false); // setting webview listeners browser.setlistener(this, this); // set javascript , zoom , other settings browser.requestfocus(); browser.getsettings().setjavascriptenabled(true); browser.getsettings().setbuiltinzoomcontrols(false); browser.getsettings().setappcacheenabled(true); browser.getsettings().setdatabaseenabled(true); browser.getsettings().setdomstorageenabled(true); // below required geolocation browser.setgeolocationenabled(true); // 3rd party plugins (on older devices) browser.getsettings().setpluginstate(pluginstate.on); if (config.multi_windows) { browser.getsettings().setjavascriptcanopenwindowsautomatically(true); browser.getsettings().setsupportmultiplewindows(true); } webclient = new webtoappwebclient(getactivity(), browser); browser.setwebviewclient(webclient); chromeclient = new webtoappchromeclient(getactivity(), rl, browser, swipelayout, progressbar); browser.setwebchromeclient(chromeclient); // load url (if connection available if (webclient.hasconnectivity(mainurl, true)) { string pushurl = ((app) getactivity().getapplication()).getpushurl(); if (pushurl != null){ browser.loadurl(pushurl); } else { browser.loadurl(mainurl); } } } @override public void onrefresh() { browser.reload(); } @suppresslint("newapi") @override public void onpause() { super.onpause(); browser.onpause(); } @override public void ondestroy() { super.ondestroy(); browser.ondestroy(); } @suppresslint("newapi") @override public void onresume() { super.onresume(); browser.onresume(); } @suppresslint("newapi") @override public void ondownloadrequested(string url, string useragent, string contentdisposition, string mimetype, long contentlength) { if (!haspermissiontodownload(getactivity())) return; string filename = null; try { filename = new getfileinfo().execute(url).get(); } catch (interruptedexception e) { e.printstacktrace(); } catch (executionexception e) { e.printstacktrace(); } if (filename == null) { string fileextenstion = mimetypemap.getfileextensionfromurl(url); filename = urlutil.guessfilename(url, null, fileextenstion); } if (advancedwebview.handledownload(getactivity(), url, filename)) { toast.maketext(getactivity(), getresources().getstring(r.string.download_done), toast.length_short).show(); ondownloadinterstitialad(); } else { toast.maketext(getactivity(), getresources().getstring(r.string.download_fail), toast.length_short).show(); } } private static boolean haspermissiontodownload(final activity context) { if (build.version.sdk_int < build.version_codes.m || contextcompat.checkselfpermission(context, manifest.permission.write_external_storage) == packagemanager.permission_granted ) return true; alertdialog.builder builder = new alertdialog.builder(context); builder.setmessage(r.string.download_permission_explaination); builder.setpositivebutton(r.string.common_permission_grant, new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog, int id) { // fire off async request permission // show standard permission request dialog ui if(build.version.sdk_int >= build.version_codes.m) context.requestpermissions(new string[]{manifest.permission.write_external_storage},1); } }); alertdialog dialog = builder.create(); dialog.show(); return false; } @override public void onpagestarted(string url, bitmap favicon) { if (firstload == 0 && mainactivity.getcollapsingactionbar()){ ((mainactivity) getactivity()).showtoolbar(this); firstload = 1; } else if (firstload == 0){ firstload = 1; } } /** * show interstitial ad */ private void ondownloadinterstitialad(){ final interstitialad minterstitialad = new interstitialad(getactivity()); minterstitialad.setadunitid(getresources().getstring(r.string.ad_interstitial_id)); adrequest adrequestinter = new adrequest.builder().addtestdevice(adrequest.device_id_emulator).build(); minterstitialad.setadlistener(new adlistener() { @override public void onadloaded() { minterstitialad.show(); } }); minterstitialad.loadad(adrequestinter); } @override public void onpagefinished(string url) { //showinterstitial(); } @override public void onpageerror(int errorcode, string description, string failingurl) { // todo auto-generated method stub } @override public void onexternalpagerequest(string url) { // todo auto-generated method stub } @override public void onactivityresult(int requestcode, int resultcode, intent data) { super.onactivityresult(requestcode, resultcode, data); browser.onactivityresult(requestcode, resultcode, data); } }
and main activity:
public class mainactivity extends appcompatactivity implements drawerfragment.drawerfragmentlistener{ //views public toolbar mtoolbar; public view mheaderview; public tablayout mslidingtablayout; public swipeableviewpager mviewpager; //app navigation structure private navigationadapter madapter; private drawerfragment drawerfragment; private webfragment currentanimatingfragment = null; private int currentanimation = 0; //identify toolbar state private static int no = 0; private static int hiding = 1; private static int showing = 2; //keep track of interstitials show private int interstitialcount = 0; sharedpreferences prefs; public firebaseauth authtt; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); authtt = firebaseauth.getinstance(); mtoolbar = (toolbar) findviewbyid(r.id.toolbar); mheaderview = (view) findviewbyid(r.id.header_container); mslidingtablayout = (tablayout) findviewbyid(r.id.tabs); mviewpager = (swipeableviewpager) findviewbyid(r.id.pager); setsupportactionbar(mtoolbar); madapter = new navigationadapter(getsupportfragmentmanager(), this); final intent intent = getintent(); final string action = intent.getaction(); if (intent.action_view.equals(action)) { string data = intent.getdatastring(); ((app) getapplication()).setpushurl(data); } haspermissiontodo(this, config.permissions_required); relativelayout.layoutparams lp = (relativelayout.layoutparams) mviewpager.getlayoutparams(); if ((config.hide_actionbar && gethidetabs()) || ((config.hide_actionbar || gethidetabs()) && getcollapsingactionbar())){ lp.topmargin = 0; } else if ((config.hide_actionbar || gethidetabs()) || (!config.hide_actionbar && !gethidetabs() && getcollapsingactionbar())){ lp.topmargin = getactionbarheight(); } else if (!config.hide_actionbar && !gethidetabs()){ lp.topmargin = getactionbarheight() * 2; } if (config.use_drawer) { getsupportactionbar().setdisplayshowhomeenabled(true); getsupportactionbar().setlogo(r.mipmap.ic_launcher); getsupportactionbar().setdisplayuselogoenabled(true); drawerfragment = (drawerfragment) getsupportfragmentmanager().findfragmentbyid(r.id.fragment_navigation_drawer); drawerfragment.setup(r.id.fragment_navigation_drawer, (drawerlayout) findviewbyid(r.id.drawer_layout), mtoolbar); drawerfragment.setdrawerlistener(this); } else { ((drawerlayout) findviewbyid(r.id.drawer_layout)).setdrawerlockmode(drawerlayout.lock_mode_locked_closed); } mviewpager.setlayoutparams(lp); mviewpager.setadapter(madapter); mviewpager.setoffscreenpagelimit(mviewpager.getadapter().getcount() - 1); mslidingtablayout.setselectedtabindicatorcolor(getresources().getcolor(r.color.accent)); mslidingtablayout.setupwithviewpager(mviewpager); mslidingtablayout.setontabselectedlistener(new tablayout.ontabselectedlistener() { @override public void ontabselected(tablayout.tab tab) { if (getcollapsingactionbar()) { showtoolbar(getfragment()); } mviewpager.setcurrentitem(tab.getposition()); showinterstitial(); } @override public void ontabunselected(tablayout.tab tab) { } @override public void ontabreselected(tablayout.tab tab) { } }); (int = 0; < mslidingtablayout.gettabcount(); i++) { if (config.icons.length > && config.icons[i] != 0) { mslidingtablayout.gettabat(i).seticon(config.icons[i]); } } // admob if (!getresources().getstring(r.string.ad_banner_id).equals("")) { // adview resource , load request. adview adview = (adview) findviewbyid(r.id.adview); adrequest adrequest = new adrequest.builder().build(); adview.loadad(adrequest); } else { adview adview = (adview) findviewbyid(r.id.adview); adview.setvisibility(view.gone); } // application rating alertdialog.builder builder = new alertdialog.builder(this) .settitle(getstring(r.string.rate_title)) .setmessage(string.format(getstring(r.string.rate_message), getstring(r.string.app_name))) .setpositivebutton(getstring(r.string.rate_yes), null) .setnegativebutton(getstring(r.string.rate_never), null) .setneutralbutton(getstring(r.string.rate_later), null); new apprate(this) .setshowifapphascrashed(false) .setmindaysuntilprompt(2) .setminlaunchesuntilprompt(2) .setcustomdialog(builder) .init(); // showing splash screen if (config.splash) { findviewbyid(r.id.imageloading1).setvisibility(view.visible); //getfragment().browser.setvisibility(view.gone); } } // using button of device @override public void onbackpressed() { view customview = null; webchromeclient.customviewcallback customviewcallback = null; if (getfragment().chromeclient != null) { customview = getfragment().chromeclient.getcustomview(); customviewcallback = getfragment().chromeclient.getcustomviewcallback(); } if ((customview == null) && getfragment().browser.cangoback()) { getfragment().browser.goback(); } else if (customview != null && customviewcallback != null) { customviewcallback.oncustomviewhidden(); } else { super.onbackpressed(); } } @override public void onconfigurationchanged(configuration newconfig) { super.onconfigurationchanged(newconfig); } @override protected void onpause() { super.onpause(); } @override protected void onresume() { super.onresume(); } public void settitle(string title) { if (madapter != null && madapter.getcount() == 1 && !config.use_drawer && !config.static_toolbar_title) getsupportactionbar().settitle(title); } public webfragment getfragment(){ return (webfragment) madapter.getcurrentfragment(); } boolean gethidetabs(){ if (madapter.getcount() == 1 || config.use_drawer){ return true; } else { return config.hide_tabs; } } @override public boolean ondraweritemselected(view view, int position) { string url = config.urls[position]; if (webtoappwebclient.urlshouldopenexternally(url)){ try { view.getcontext().startactivity( new intent(intent.action_view, uri.parse(url))); } catch(activitynotfoundexception e) { if (url.startswith("intent://")) { view.getcontext().startactivity( new intent(intent.action_view, uri.parse(url.replace("intent://", "http://")))); } else { toast.maketext(this, getresources().getstring(r.string.no_app_message), toast.length_long).show(); } } return false; } else { getfragment().browser.loadurl("about:blank"); getfragment().setbaseurl(config.urls[position]); showinterstitial(); return true; } } private static boolean haspermissiontodo(final activity context, final string[] permissions) { boolean onedenied = false; (string permission : permissions) { if (build.version.sdk_int >= build.version_codes.m && contextcompat.checkselfpermission(context, permission) != packagemanager.permission_granted) onedenied = true; } if (!onedenied) return true; android.support.v7.app.alertdialog.builder builder = new android.support.v7.app.alertdialog.builder(context); builder.setmessage(r.string.common_permission_explaination); builder.setpositivebutton(r.string.common_permission_grant, new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog, int id) { // fire off async request permission // show standard permission request dialog ui if(build.version.sdk_int >= build.version_codes.m) context.requestpermissions(permissions,1); } }); android.support.v7.app.alertdialog dialog = builder.create(); dialog.setcanceledontouchoutside(false); dialog.show(); return false; } }
Comments
Post a Comment