mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-27 07:58:49 +01:00
expect array of message bodies rather than just one
This commit is contained in:
parent
120748416b
commit
2e30ccd4c6
2 changed files with 26 additions and 12 deletions
|
@ -25,6 +25,7 @@ import android.content.Context;
|
|||
import android.content.Intent;
|
||||
import com.google.android.gcm.GCMBaseIntentService;
|
||||
import com.google.android.gcm.GCMRegistrar;
|
||||
import org.json.JSONArray;
|
||||
|
||||
public class GCMIntentService extends GCMBaseIntentService {
|
||||
|
||||
|
@ -63,11 +64,20 @@ public class GCMIntentService extends GCMBaseIntentService {
|
|||
RelayReceiver.RestartTimer( context, true );
|
||||
}
|
||||
|
||||
value = intent.getStringExtra( "msg64" );
|
||||
value = intent.getStringExtra( "msgs64" );
|
||||
if ( null != value ) {
|
||||
String connname = intent.getStringExtra( "connname" );
|
||||
if ( null != connname ) {
|
||||
RelayService.processMsg( context, connname, value );
|
||||
try {
|
||||
JSONArray msgs64 = new JSONArray( value );
|
||||
String[] strs64 = new String[msgs64.length()];
|
||||
for ( int ii = 0; ii < strs64.length; ++ii ) {
|
||||
strs64[ii] = msgs64.optString(ii);
|
||||
}
|
||||
RelayService.processMsgs( context, connname, strs64 );
|
||||
} catch (org.json.JSONException jse ) {
|
||||
DbgUtils.loge( jse );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -40,16 +40,15 @@ public class RelayService extends Service {
|
|||
private static final int MAX_BUF = MAX_SEND - 2;
|
||||
|
||||
private static final String CMD_STR = "CMD";
|
||||
private static final int PROCESS_MSG = 1;
|
||||
private static final String MSG = "MSG";
|
||||
private static final int PROCESS_MSGS = 1;
|
||||
private static final String MSGS = "MSGS";
|
||||
private static final String RELAY_ID = "RELAY_ID";
|
||||
|
||||
public static void processMsg( Context context, String relayId,
|
||||
String msg64 )
|
||||
public static void processMsgs( Context context, String relayId,
|
||||
String[] msgs64 )
|
||||
{
|
||||
byte[] msg = XwJNI.base64Decode( msg64 );
|
||||
Intent intent = getIntentTo( context, PROCESS_MSG )
|
||||
.putExtra( MSG, msg )
|
||||
Intent intent = getIntentTo( context, PROCESS_MSGS )
|
||||
.putExtra( MSGS, msgs64 )
|
||||
.putExtra( RELAY_ID, relayId );
|
||||
context.startService( intent );
|
||||
}
|
||||
|
@ -86,13 +85,18 @@ public class RelayService extends Service {
|
|||
{
|
||||
int cmd = intent.getIntExtra( CMD_STR, -1 );
|
||||
switch( cmd ) {
|
||||
case PROCESS_MSG:
|
||||
case PROCESS_MSGS:
|
||||
String[] relayIDs = new String[1];
|
||||
relayIDs[0] = intent.getStringExtra( RELAY_ID );
|
||||
long[] rowIDs = DBUtils.getRowIDsFor( this, relayIDs[0] );
|
||||
if ( 0 < rowIDs.length ) {
|
||||
byte[][][] msgs = new byte[1][1][1];
|
||||
msgs[0][0] = intent.getByteArrayExtra( MSG );
|
||||
String[] msgs64 = intent.getStringArrayExtra( MSGS );
|
||||
int count = msgs64.length;
|
||||
|
||||
byte[][][] msgs = new byte[1][count][];
|
||||
for ( int ii = 0; ii < count; ++ii ) {
|
||||
msgs[0][ii] = XwJNI.base64Decode( msgs64[ii] );
|
||||
}
|
||||
process( msgs, rowIDs, relayIDs );
|
||||
}
|
||||
break;
|
||||
|
|
Loading…
Add table
Reference in a new issue