room names are user-created and need to be URLEncoded to e.g. escape

spaces.
This commit is contained in:
Andy2 2011-06-09 06:38:43 -07:00
parent d43d789820
commit e097b15071
2 changed files with 21 additions and 8 deletions

View file

@ -76,7 +76,7 @@
<string name="app_version">4.4 beta 28</string>
<string name="app_market_url">https://market.android.com/search?q=pname:org.eehouse.android.xw4</string>
<!--string name="app_market_url">market://search?q=pname:org.eehouse.android.xw4</string-->
<string name="game_urlf">http://%1$s/redir.php?room=%2$s\u0026lang=%3$d</string>
<string name="game_urlf">http://%1$s/redir.php?lang=%2$d</string>
<!--string name="dict_url">http://10.0.2.2/~eehouse/and_dicts</string-->

View file

@ -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 )