From e097b15071b5f0e9beb4ac190b2d209bd44da456 Mon Sep 17 00:00:00 2001 From: Andy2 Date: Thu, 9 Jun 2011 06:38:43 -0700 Subject: [PATCH] room names are user-created and need to be URLEncoded to e.g. escape spaces. --- .../XWords4/res/values/common_rsrc.xml | 2 +- .../org/eehouse/android/xw4/GameUtils.java | 27 ++++++++++++++----- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/xwords4/android/XWords4/res/values/common_rsrc.xml b/xwords4/android/XWords4/res/values/common_rsrc.xml index 879554d93..8fffbd16b 100644 --- a/xwords4/android/XWords4/res/values/common_rsrc.xml +++ b/xwords4/android/XWords4/res/values/common_rsrc.xml @@ -76,7 +76,7 @@ 4.4 beta 28 https://market.android.com/search?q=pname:org.eehouse.android.xw4 - http://%1$s/redir.php?room=%2$s\u0026lang=%3$d + http://%1$s/redir.php?lang=%2$d diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameUtils.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameUtils.java index 79907ce79..b438a5d07 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameUtils.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameUtils.java @@ -28,6 +28,7 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.InputStream; +import java.net.URLEncoder; import java.nio.channels.FileChannel; import java.util.ArrayList; import java.util.Arrays; @@ -396,14 +397,26 @@ public class GameUtils { Random random = new Random(); String inviteID = String.format( "%x", random.nextInt() ).substring( 0, 4 ); - String gameUrl = String.format( format, host, room, lang, inviteID ); - format = context.getString( R.string.invite_bodyf ); - String appUrl = context.getString( R.string.app_market_url ); - String message = String.format( format, gameUrl, appUrl ); - intent.putExtra( Intent.EXTRA_TEXT, message ); + StringBuilder query = + new StringBuilder(String.format( format, host, lang, inviteID )); + query.append("&room="); + String gameUrl = null; + try { + query.append( URLEncoder.encode(room, "UTF-8") ); + gameUrl = query.toString(); + } catch ( java.io.UnsupportedEncodingException uee ) { + Utils.logf( "%s", uee.toString() ); + } - String chooserMsg = context.getString( R.string.invite_chooser ); - context.startActivity( Intent.createChooser( intent, chooserMsg ) ); + if ( null != gameUrl ) { + format = context.getString( R.string.invite_bodyf ); + String appUrl = context.getString( R.string.app_market_url ); + String message = String.format( format, gameUrl, appUrl ); + intent.putExtra( Intent.EXTRA_TEXT, message ); + + String chooserMsg = context.getString( R.string.invite_chooser ); + context.startActivity( Intent.createChooser( intent, chooserMsg ) ); + } } public static boolean gameDictsHere( Context context, String path )