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 03be71b10..59e482470 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameUtils.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameUtils.java @@ -548,19 +548,27 @@ public class GameUtils { if ( null == inviteID ) { inviteID = makeRandomID(); } - Uri gameUri = NetLaunchInfo.makeLaunchUri( activity, room, inviteID, - lang, dict, nPlayers ); - if ( null != gameUri ) { + String msgString; + if ( DlgDelegate.NFC_BTN == chosen ) { + msgString = NetLaunchInfo.makeLaunchJSON( activity, room, inviteID, + lang, dict, nPlayers ); + } else { + Uri gameUri = NetLaunchInfo.makeLaunchUri( activity, room, inviteID, + lang, dict, nPlayers ); + msgString = null == gameUri ? null : gameUri.toString(); + } + + if ( null != msgString ) { if ( DlgDelegate.NFC_BTN == chosen ) { - DbgUtils.logf( "wants to launch NFC" ); NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter( activity ); NdefMessage msg = new NdefMessage( new NdefRecord[] { new NdefRecord(NdefRecord.TNF_MIME_MEDIA, "application/org.eehouse.android.xw4" .getBytes(Charset.forName("US-ASCII")), - new byte[0], "Beam me up, Android!" - .getBytes(Charset.forName("US-ASCII"))) - ,NdefRecord.createApplicationRecord("org.eehouse.android.xw4") + new byte[0], msgString. + getBytes(Charset.forName("US-ASCII"))) + ,NdefRecord. + createApplicationRecord("org.eehouse.android.xw4") }); nfcAdapter.setNdefPushMessage( msg, activity ); Utils.showToast( activity, "Tap the receiving device now" ); @@ -569,7 +577,7 @@ public class GameUtils { int fmtId = choseEmail? R.string.invite_htmf : R.string.invite_txtf; int choiceID; - String message = activity.getString( fmtId, gameUri.toString() ); + String message = activity.getString( fmtId, msgString ); Intent intent = new Intent(); if ( choseEmail ) { diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesList.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesList.java index 59d3e815d..bbc802f6d 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesList.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GamesList.java @@ -1135,8 +1135,12 @@ public class GamesList extends XWExpandableListActivity // only one message sent during the beam NdefMessage msg = (NdefMessage) rawMsgs[0]; // record 0 contains the MIME type, record 1 is the AAR, if present - String txt = new String( msg.getRecords()[0].getPayload() ); - DbgUtils.logf( "got message: %s", txt ); + String data = new String( msg.getRecords()[0].getPayload() ); + + NetLaunchInfo nli = new NetLaunchInfo( data ); + if ( nli.isValid() ) { + startNewNetGame( nli ); + } } } diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/NetLaunchInfo.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/NetLaunchInfo.java index 878316cf1..df416e93a 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/NetLaunchInfo.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/NetLaunchInfo.java @@ -57,6 +57,21 @@ public class NetLaunchInfo { bundle.putBoolean( VALID, m_valid ); } + public NetLaunchInfo( String data ) + { + try { + JSONObject json = new JSONObject( data ); + room = json.getString( MultiService.ROOM ); + inviteID = json.getString( MultiService.INVITEID ); + lang = json.getInt( MultiService.LANG ); + dict = json.getString( MultiService.DICT ); + nPlayersT = json.getInt( MultiService.NPLAYERST ); + m_valid = true; + } catch ( org.json.JSONException jse ) { + m_valid = false; + } + } + public NetLaunchInfo( Bundle bundle ) { lang = bundle.getInt( LANG ); @@ -134,6 +149,25 @@ public class NetLaunchInfo { return ub.build(); } + public static String makeLaunchJSON( Context context, String room, + String inviteID, int lang, + String dict, int nPlayersT ) + { + String result = null; + try { + result = new JSONObject() + .put( MultiService.ROOM, room ) + .put( MultiService.INVITEID, inviteID ) + .put( MultiService.LANG, lang ) + .put( MultiService.DICT, dict ) + .put( MultiService.NPLAYERST, nPlayersT ) + .toString(); + } catch ( org.json.JSONException jse ) { + DbgUtils.loge( jse ); + } + return result; + } + public boolean isValid() { return m_valid;