Discussion Forums  >  Uncategorized

Replies: 22    Views: 344

frontrunner_tech
Code is Art
Profile
Posts: 20
Reg: Apr 04, 2011
Dickinson
2,850
08/24/11 09:15 AM (12 years ago)

mailto opening as website in Custom URL

Have tested this in Android v1.4, not iOS so far. Instead of opening the mail client when touching a mailto link in a Custom URL, it attempts to open as a website. <a href=mailto:[email protected]>Email</a> <a href=mailto:[email protected]?subject=test>Email</a> <a href=mailto:[email protected]?subject=test&body=test>Email</a> <a href=mailto:>Email</a> <a href=mailto:?subject=test>Email</a> <a href=mailto:?subject=test&body=test>Email</a> All of these produce the same result. The expected behavior (email client opening) occurs when browsing to the URL in the default browser (outside of Buzztouch) and touching the link.
 
frontrunner_tech
Code is Art
Profile
Posts: 20
Reg: Apr 04, 2011
Dickinson
2,850
like
08/25/11 06:00 PM (12 years ago)
Update: In the iPhone simulator, it puts the entire mailto string in the recipients field.
 
David @ buzztouch
buzztouch Evangelist
Profile
Posts: 6866
Reg: Jan 01, 2010
Monterey, CA
78,840
like
08/26/11 01:17 AM (12 years ago)
Hmm..mailto links are generally very reliable. I'de bet the HTML has something 'wrong' with it. It could be that when the device downloads and saves it it's somehow introducing something that invalidates the HTML. Hard to say. Oh, wait, Custom URL screen probabaly doesn't save the screen and just pulls it from the URL and displays it. So... in this case... Maybe have a look at the console in v1.5 with the app running. Does it show you any details when the link is tapped? a) Launch the app in Xcode (simualtor is fine) b) Open the Console window to see all sorts of useful output c) Navigation to the URL screen d) CLEAR the console so it's easier to see what's happening when you tap the link e) Tap the link. Does anything useful get printed to the console window?
 
frontrunner_tech
Code is Art
Profile
Posts: 20
Reg: Apr 04, 2011
Dickinson
2,850
like
08/26/11 08:48 AM (12 years ago)
Thanks for the response. Nothing of interest is displayed in the console. In fact, touching on the custom URL menu item displays nothing in the console, whereas touching other items in the menu produces some output in the console (but nothing bad or unusual). So maybe nothing is of interest? W3C: This document was successfully checked as XHTML Mobile Profile 1.2! Okay, I lied, it doesn't validate in production because of the AddThis widget added to the page. But for testing purposes, the widget was disabled so that it validates, added a regular mailto link and get the same result, it tries to open it as a webpage instead of opening the email client. Again, still using 1.4. We don't want to use 1.5 until the Android version comes out, but maybe 1.4 isn't supported anymore.
 
David @ buzztouch
buzztouch Evangelist
Profile
Posts: 6866
Reg: Jan 01, 2010
Monterey, CA
78,840
like
08/26/11 10:14 PM (12 years ago)
Totally missed the v1.4 thing...the console will be zero help in v1.4 - funny. We added tons and tons of info to it in v1.5 to help with these types of things exactly. Lets do this: a) Post the name of the app exactly as it appears in your control panel. b) Post the name of the menu item / screen / email link. Where is the thing to tap to see the issue. c) Post a simple 'its OK for buzztouch to download my source-code for testing' I'll get a look and figure out the issue. Can't be that tough ;-)
 
frontrunner_tech
Code is Art
Profile
Posts: 20
Reg: Apr 04, 2011
Dickinson
2,850
like
09/03/11 02:25 AM (12 years ago)
Oh WOW! Sorry it took so long. Hopefully you still remember what we are talking about: a) TR Quotes b) TR Quote of the Day -> Scroll down, touch the email icon. c) Have fun with the source code.
 
David @ buzztouch
buzztouch Evangelist
Profile
Posts: 6866
Reg: Jan 01, 2010
Monterey, CA
78,840
like
09/05/11 09:30 PM (12 years ago)
I remember. But, I don't remember iOS or Android. v1.4 or v1.5? Funny.
 
frontrunner_tech
Code is Art
Profile
Posts: 20
Reg: Apr 04, 2011
Dickinson
2,850
like
09/05/11 09:35 PM (12 years ago)
1.4 Android: Attempts to open mailto in browser, as a website. 1.4 iOS: Puts mailto in TO field.
 
David @ buzztouch
buzztouch Evangelist
Profile
Posts: 6866
Reg: Jan 01, 2010
Monterey, CA
78,840
like
09/06/11 12:13 AM (12 years ago)
OK, figured out iOS. Have a look at the HTML (view source after loading page in regular browser) of this stie: http://trqotd.frontrunnertechnologies.com The mailto link you're refering to does not have a to-address. Mobile safari on the iPhone handles this a little different than the built in WebKit that developers can use (you). Becuase you don't want a 'to address' used, you'll need to make a few adjustments to the project source code after you download it from your control panel. Find the CustomURLViewController.m file inside the ScreenControllers folder in Xcode. Scroll to about line 203 in this file and find this line: [mailer setToRecipients:[NSArray arrayWithObject:request.URL.resourceSpecifier]]; You'll also see a few lines below this were it sets the body. Commout these two lines out, or remove them altogether. These lines will now look like this if you comment them: //[mailer setToRecipients:[NSArray arrayWithObject:request.URL.resourceSpecifier]]; //[mailer setMessageBody:@ isHTML:NO]; The order they appear is not important, just make sure they are commented out.... NEXT, lets figure out the subject and body to pre-fill. Before the app does this; [self presentModalViewController:mailer animated:YES]; you'll need to paste some custom code. This custom code does a few things. First, it searches the URL in the mailto link for an ampersand. If one is found, it splits the url into a few parts at the ampersand. Next, it looks at the first part to figure out the subject, then it figures out the second part to set the body... //split up the mailto: string into multiple parts... NSArray *parts = [urlString componentsSeparatedByString:@&]; //if we have more than zero parts, figure out subject... if([parts count] > 0){ NSString *tmpSubject = [parts objectAtIndex:0]; tmpSubject = [tmpSubject stringByReplacingOccurrencesOfString:@mailto: withString:@]; tmpSubject = [tmpSubject stringByReplacingOccurrencesOfString:@?subject= withString:@]; tmpSubject = [tmpSubject stringByReplacingOccurrencesOfString:@%20 withString:@ ]; [mailer setSubject:tmpSubject]; } //if we have more than 1 part, figure out the body... NSString *tmpBody = [parts objectAtIndex:1]; tmpBody = [tmpBody stringByReplacingOccurrencesOfString:@body= withString:@]; tmpBody = [tmpBody stringByReplacingOccurrencesOfString:@%20 withString:@ ]; [mailer setMessageBody:tmpBody isHTML:NO]; This forum will remove the double quotes around the string values, you'll need to add those in Xcode when you paste this. If you're unsure how to do this, look down the code some, you'll see how string values are surrounded with quotes. Looking at Android.
 
David @ buzztouch
buzztouch Evangelist
Profile
Posts: 6866
Reg: Jan 01, 2010
Monterey, CA
78,840
like
09/06/11 12:55 AM (12 years ago)
Android: Same fix in .java instead of objective c. In Eclipse, after downloading your project... find Screen_customURL.java in the /src directory. Scroll down to about line 102 and find this: //anything with an .zip extension if(url.contains(.zip)){ useNativeIntent = 1; } We'll add some custom code below this that looks for 'mailto' in the URL. If it find it, process some logic like the iOS fix. //anything with an mailto tag if(url.contains(mailto)){ //prepare an email intent.. Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); emailIntent.setType(text/plain); //set a blank to address... emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, ); //split URL into parts.. String[] parts = url.split(&); //set the subject.. if(parts.length > 0){ String tmpSubject = parts[0]; tmpSubject = tmpSubject.replace(mailto:, ); tmpSubject = tmpSubject.replace(subject=:, ); tmpSubject = tmpSubject.replace(%20, ); emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, tmpSubject); } //set the body.. if(parts.length > 1){ String tmpBody = parts[1]; tmpBody = tmpBody.replace(body=, ); tmpBody = tmpBody.replace(body=, ); tmpBody = tmpBody.replace(%20, ); emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, tmpBody); } //start the activity startActivity(emailIntent); //flag, bail useNativeIntent = 1; return false; } That code should be pasted just ABOVE the line that reads... //allow loading of this url. I have tested this on several devices, works as expected. The trick in all of this is that you are using an IMPROPERLY formed mailto: tag. The RFC specification clearly states that malto tags must contain a to-address and MAY contain other information like subject and body. These code snippets (that I just wrote) work around this idea. Good luck.
 
frontrunner_tech
Code is Art
Profile
Posts: 20
Reg: Apr 04, 2011
Dickinson
2,850
like
09/06/11 01:14 PM (12 years ago)
Great, thank you! Your support is outstanding. For anyone else who may stuble upon this, I made a few modifications: Removed this duplicate line of code for Android: tmpBody = tmpBody.replace(body=, ); Added an if statement for this block in iOS to check if parts > 1. Not sure what would happen if it isn't greater than 1, but I think it would probably flip us off: //if we have more than 1 part, figure out the body... if([parts count] > 1){ NSString *tmpBody = [parts objectAtIndex:1]; tmpBody = [tmpBody stringByReplacingOccurrencesOfString:@body= withString:@]; tmpBody = [tmpBody stringByReplacingOccurrencesOfString:@%20 withString:@ ]; [mailer setMessageBody:tmpBody isHTML:NO]; } Thanks for doing that rather than just saying, Well, your email tag doesn't follow RFC specifications, therefore it will not work. As you can probably see, the purpose of leaving it blank is because at this point, we don't know who the user will be sending the email to. It's been a while so I could be wrong, but I'm pretty sure that for iOS, even with an email address specified, it was inserting the entire mailto string in the to field: [email protected]?subject=Subject%20Text&body=Body%20Text. In Android, it was just throwing the error. If I have some time in the next couple of days, maybe I'll test again to confirm. This behavior only happened from within Buzztouch, but browsing to the page outside of Buzztouch using the default browser produced the desired results. I've only tested on the emulators, but I noticed the following with Android: 1. It appears to compose an MMS message instead of an email. This could very well be that the email client isn't configured on the emulator, I'll post back after testing on an actual Android device. 2. It displays the default error page saying that it couldn't find the website mailto:.... You can see it for a brief instant when clicking the email link, the email modal covers it and after getting out of the message popup, the ugly error page is displayed. 3. iOS has the desired behavior: When exiting the email screen, the originating page (the one with the email link) is displayed.
 
frontrunner_tech
Code is Art
Profile
Posts: 20
Reg: Apr 04, 2011
Dickinson
2,850
like
09/06/11 01:31 PM (12 years ago)
//flag, bail useNativeIntent = 1; return false; Should this be return true to prevent this from executing: //allow loading of this URL if(useNativeIntent == 0){ //showProgress(Loading..,This may take a moment if you have a slow internet connection.); loadBrowser(url); return true; } //let phone detemrine intent to use if(bolDone == 0){ //let phone determine which intent to launch... Intent theIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); startActivity(theIntent); return false; } This solves the problem, but I didn't look much further to see if returning at this point would have any bad implications.
 
frontrunner_tech
Code is Art
Profile
Posts: 20
Reg: Apr 04, 2011
Dickinson
2,850
like
09/06/11 02:53 PM (12 years ago)
Yep, works great on hardware device. Touching the mail link opens a window promting the user on how they want to send the message, using SMS or the email client, while putting the data in the appropriate fields. Changing this //flag, bail useNativeIntent = 1; return false; to //flag, bail useNativeIntent = 1; return true; prevents Android from trying to open mailto as a webpage.
 
David @ buzztouch
buzztouch Evangelist
Profile
Posts: 6866
Reg: Jan 01, 2010
Monterey, CA
78,840
like
09/07/11 12:07 AM (12 years ago)
Whoo hoo. Great tip. Glad you got it working.
 
ATRAIN53
Code is Art
Profile
Posts: 1755
Reg: Nov 17, 2011
Chicago
26,450
like
12/08/11 01:41 PM (12 years ago)
i'm stuck here now with my mailto links on a custom URL not working. they try to launch as web page as posted here. so this post seems to be on target. i tried to post the chunk of code below as suggested between the //anything with an .zip extension if(url.contains(.zip)){ useNativeIntent = 1; } and //allow loading of this url sections but Eclipse now tells me my Screen_CustomURL has errors. this is the code snippet i tried to paste. i even changed that flag/bail return value as noted by the frontrunner //anything with an mailto tag if(url.contains(mailto)){ //prepare an email intent.. Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); emailIntent.setType(text/plain); //set a blank to address... emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, ); //split URL into parts.. String[] parts = url.split(&); //set the subject.. if(parts.length > 0){ String tmpSubject = parts[0]; tmpSubject = tmpSubject.replace(mailto:, ); tmpSubject = tmpSubject.replace(subject=:, ); tmpSubject = tmpSubject.replace(%20, ); emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, tmpSubject); } //set the body.. if(parts.length > 1){ String tmpBody = parts[1]; tmpBody = tmpBody.replace(body=, ); tmpBody = tmpBody.replace(%20, ); emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, tmpBody); } //start the activity startActivity(emailIntent); //flag, bail useNativeIntent = 1; return true; }
 
David @ buzztouch
buzztouch Evangelist
Profile
Posts: 6866
Reg: Jan 01, 2010
Monterey, CA
78,840
like
12/09/11 12:03 AM (12 years ago)
Tough to say with the forum hacking up the code. If Eclispe is showing the error it's usually pretty good at isolating it on the line where the error is. Little red icon usually? See if you can figure out what line the error is on. And, if you can, make a plain text file with your Screen_CustomURL.java class code with the error (.txt extension), plop it on a DropBox and post the URL here.
 
ATRAIN53
Code is Art
Profile
Posts: 1755
Reg: Nov 17, 2011
Chicago
26,450
like
12/09/11 08:21 AM (12 years ago)
Thanks David- i suspect the forum and formatting hacked up the code as well. the one thing i do understand about code is that it's very picky. one space, comma or character out of place and it is a no go. and you can spend a day trying to find it... this is the main error Eclipse kicks out when i added that code you created above to my Screen_CustomURL.java mailto cannot be resolved to a variable i included a doc with all the Eclipse errors and a copy of the Screen_CustomURL.java on a dropbox- http://dl.dropbox.com/u/52751145/eclipse%20errors.txt http://dl.dropbox.com/u/52751145/Screen_CustomURL.java any help is most appreciated!
 
David @ buzztouch
buzztouch Evangelist
Profile
Posts: 6866
Reg: Jan 01, 2010
Monterey, CA
78,840
like
12/12/11 10:12 PM (12 years ago)
Gone for a few days, re-visiting this. You'll need to get your head around a basic JAVA idea. When you're dealing with string type data (strings are workds, not numbers, dates, decimals) you need to wrap these in quotation marks. Example: if(url.contains(mailto) Needs to be if(url.contains('mailto') I entered single quote in this example, in Eclipse and Java use a double quote. There are lots and lots of places where you're using a string value but do not have quotes around the value in the sample .java file you have on DropBox (I love dropBox). Example: url.split(&); should be url.split('&'); Example: tmpSubject.replace(mailto:,); should be tmpSubject.replace('mailto:',''); Again, these examples show single quotes in the forum, use double quotes. This type of issue is in many places and the errors you posted (the other drop box file) show clues as to where to look. You're right, JAVA, and other programming languages, expect precision so you need to be sure the syntax is right or you'll have lots and lots of compiler errors.
 
MobileMart
Aspiring developer
Profile
Posts: 5
Reg: Oct 25, 2011
UK
750
like
12/20/11 04:41 PM (12 years ago)
Am trying to do something similar but am totally lost here. My Xcode doesn't have the folders or files you mention above. I'm using the latest versions on the early adopter system. can you help? Basically Im trying to send an email from a custom html page ... without an email address but with a subject and a body message. I can do this on a normal html file but not using buzz touch on ios. Thanks
 
ATRAIN53
Code is Art
Profile
Posts: 1755
Reg: Nov 17, 2011
Chicago
26,450
like
02/28/12 01:03 PM (12 years ago)
anyone able to resolve this in BT 1.4 for Android? my mailto and tel links still try to open in the web browser....
 
ATRAIN53
Code is Art
Profile
Posts: 1755
Reg: Nov 17, 2011
Chicago
26,450
like
02/28/12 03:09 PM (12 years ago)
this seems to be the 2 lines that are holding me up: Dave suggested adding this: //set a blank to address... emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, ); that generates errors when i put them in my ScreenCustomURL if i put this in my file instead //set a blank to address... emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,); it will compile and launch- but it's not launching the email app in droid when you tap the test that is hyperlined on the custom HTML screen it's just halting that app and then displaying Activity XXXXXXXXX (in application XXXXXXXX) is not responding close, but not quite there....
 
signals23
Android Fan
Profile
Posts: 12
Reg: Jan 17, 2012
Cleveland
120
like
03/28/12 02:40 PM (12 years ago)
I know this is an old thread, but it helped me get both the tel: and mailto: to work with the code below for v1.4. It's different than the above, but works for what I need it to do. I set it in between what is mentioned above and also got it to work in CustomHTML, but that took some more hacking. //anything with a tel tag if (url.startsWith("tel:")) { Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); startActivity(intent); //flag, bail useNativeIntent = 1; return false; } //anything with a mailto tag if(url.contains("mailto")){ prepare an email intent.. Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); String[] parse_email = url.split(":"); emailIntent.setType("text/plain"); emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{parse_email[1]}); emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "From BPC App"); //start the activity startActivity(emailIntent); //flag, bail useNativeIntent = 1; return false; }
 
signals23
Android Fan
Profile
Posts: 12
Reg: Jan 17, 2012
Cleveland
120
like
03/28/12 02:41 PM (12 years ago)
"prepare an email intent.." above should be commented out with //.
 

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.