Discussion Forums  >  Plugins, Customizing, Source Code

Replies: 4    Views: 1120

Paul Rogers
Android Fan
Profile
Posts: 2524
Reg: May 30, 2011
UK
35,740
11/22/12 08:02 AM (13 years ago)

Android - Open link in iframe in the native browser

This has got limited use, but might be useful for someone. When you have a custom url that contains an iframe and the iframe contains a link, the link opens up in the iframe. In a lot of cases this isn't an issue, but say you have an iframed banner of 300x50, the destination url will open in the 300x50 iframe. Not good! (target="_blank" or "_new" won't make a difference). This bit of code picks up the destination url and forces it to open in the native browser. In BT_screen_customURL.java, around line 162, add this code: @Override public void onLoadResource (WebView view, String url) { if (url.contains("google")||(url.contains("bbcnews")||(url.contains("another")||(url.contains("and-another")||(url.contains("and-so-on")||(url.contains("and-another")) ) ) ) ) ) { if(view.getHitTestResult().getType() > 0){ view.getContext().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url))); view.stopLoading(); } } } Add it just after: //do not try to load the URL.. return true; } } So the code picks up keywords in the urls. You can add as many or as few as you like, just follow the pattern and keep track of the amount of closing brackets for each keyword! Hope this helps someone! *edit ughhh, sorry for the non-formatting!
 
mrDavid
BTMods.com
Profile
Posts: 3936
Reg: May 21, 2011
San Diego, CA
51,910
like
11/22/12 08:16 AM (13 years ago)
Hey @rave - awesome! Id recommend doing http://pastebin.com/ with Syntax Highlighting for code snippets in the buzztouch forum. Super useful. Speaking of useful, this code should be awesome for some :) Nice to see you releasing some new snippets again! Cheers, David https://buzztouchmods.com
 
Sandeep
Android Fan
Profile
Posts: 1260
Reg: Feb 01, 2012
Miraj, India
25,250
like
11/22/12 09:57 AM (13 years ago)
Hi Rave, thanks for sharing. This is really helpful.
 
Paul Rogers
Android Fan
Profile
Posts: 2524
Reg: May 30, 2011
UK
35,740
like
11/22/12 10:00 AM (13 years ago)
Thanks David, I'll try pastebin next time. Been too busy to do much really, just dipping into the forum now and again. Thanks Sandeep! I sometimes use my own banner wall which is a webpage in the assets folder, but I use mobile ad networks who require ads to be on an actual website, so I iframe the webpage on my site in the webpage in the assets folder, if you see what I mean. This solution works perfectly for my needs, hope it's useful for others too.
 
AlmaR
Lost but trying
Profile
Posts: 73
Reg: Jun 13, 2011
location unknow...
5,630
like
03/01/13 02:55 PM (12 years ago)
From @perrytheweaver: In the Eclipse BZ project force html links to load in mobile phone's native browser: /src/com/nameofyourprogramapp/BT_act_controller.java canLoadDocumentInWebView() Add a file type (or url snippet) to: doNotLoadList.add("youtube.com"); doNotLoadList.add("youtu.be"); https://www.buzztouch.com/forum/thread.php?tid=2AA2085F8EE542275D3CADB&fid=5FE1FB2355A48AD674A6CA3&sortColumn=FT.id&sortUpDown=DESC&currentPage=1
 

Login + Screen Name Required to Post

pointerLogin to participate so you can start earning points. Once you're logged in (and have a screen name entered in your profile), you can subscribe to topics, follow users, and start learning how to make apps like the pros.