mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-16 15:41:16 +01:00
Docs say should allow GCM to reregister on app upgrade. And that the
registrar takes care of storing devid. So app version when registration arrives, and get from registrar except after an upgrade.
This commit is contained in:
parent
9a4a8c7b26
commit
cefc13a2cd
4 changed files with 33 additions and 13 deletions
|
@ -68,7 +68,7 @@
|
|||
<string name="key_sms_phones">key_sms_phones</string>
|
||||
<string name="key_connstat_data">key_connstat_data</string>
|
||||
<string name="key_dev_id">key_dev_id</string>
|
||||
<string name="key_gcm_regid">key_gcm_regid</string>
|
||||
<string name="key_gcmvers_regid">key_gcmvers_regid</string>
|
||||
<string name="key_relay_regid">key_relay_regid</string>
|
||||
<string name="key_checked_sms">key_checked_sms</string>
|
||||
|
||||
|
|
|
@ -78,15 +78,10 @@ public class GCMIntentService extends GCMBaseIntentService {
|
|||
try {
|
||||
GCMRegistrar.checkDevice( app );
|
||||
// GCMRegistrar.checkManifest( app );
|
||||
final String regId = GCMRegistrar.getRegistrationId( app );
|
||||
String regId = XWPrefs.getGCMDevID( app );
|
||||
if (regId.equals("")) {
|
||||
GCMRegistrar.register( app, GCMConsts.SENDER_ID );
|
||||
}
|
||||
|
||||
String curID = XWPrefs.getGCMDevID( app );
|
||||
if ( null == curID || ! curID.equals( regId ) ) {
|
||||
XWPrefs.setGCMDevID( app, regId );
|
||||
}
|
||||
} catch ( UnsupportedOperationException uoe ) {
|
||||
DbgUtils.logf( "Device can't do GCM." );
|
||||
} catch ( Exception whatever ) {
|
||||
|
|
|
@ -24,6 +24,7 @@ import android.content.Context;
|
|||
import android.content.SharedPreferences;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.text.TextUtils;
|
||||
import com.google.android.gcm.GCMRegistrar;
|
||||
import java.util.ArrayList;
|
||||
import java.util.ArrayList;
|
||||
|
||||
|
@ -112,6 +113,24 @@ public class XWPrefs {
|
|||
return result;
|
||||
}
|
||||
|
||||
public static int getPrefsInt( Context context, int keyID, int defaultValue )
|
||||
{
|
||||
String key = context.getString( keyID );
|
||||
SharedPreferences sp = PreferenceManager
|
||||
.getDefaultSharedPreferences( context );
|
||||
return sp.getInt( key, defaultValue );
|
||||
}
|
||||
|
||||
public static void setPrefsInt( Context context, int keyID, int newValue )
|
||||
{
|
||||
SharedPreferences sp = PreferenceManager
|
||||
.getDefaultSharedPreferences( context );
|
||||
SharedPreferences.Editor editor = sp.edit();
|
||||
String key = context.getString( keyID );
|
||||
editor.putInt( key, newValue );
|
||||
editor.commit();
|
||||
}
|
||||
|
||||
public static boolean getPrefsBoolean( Context context, int keyID,
|
||||
boolean defaultValue )
|
||||
{
|
||||
|
@ -186,22 +205,26 @@ public class XWPrefs {
|
|||
|
||||
public static void setGCMDevID( Context context, String devID )
|
||||
{
|
||||
setPrefsString( context, R.string.key_gcm_regid, devID );
|
||||
int curVers = Utils.getAppVersion( context );
|
||||
setPrefsInt( context, R.string.key_gcmvers_regid, curVers );
|
||||
clearPrefsKey( context, R.string.key_relay_regid );
|
||||
}
|
||||
|
||||
public static String getGCMDevID( Context context )
|
||||
{
|
||||
String result = getPrefsString( context, R.string.key_gcm_regid );
|
||||
if ( result.equals("") ) {
|
||||
result = null;
|
||||
int curVers = Utils.getAppVersion( context );
|
||||
int storedVers = getPrefsInt( context, R.string.key_gcmvers_regid, 0 );
|
||||
String result;
|
||||
if ( 0 != storedVers && storedVers < curVers ) {
|
||||
result = ""; // Don't trust what registrar has
|
||||
} else {
|
||||
result = GCMRegistrar.getRegistrationId( context );
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static void clearGCMDevID( Context context )
|
||||
{
|
||||
clearPrefsKey( context, R.string.key_gcm_regid );
|
||||
clearRelayDevID( context );
|
||||
}
|
||||
|
||||
|
|
|
@ -102,7 +102,9 @@ public class UtilCtxtImpl implements UtilCtxt {
|
|||
typ = UtilCtxt.ID_TYPE_RELAY;
|
||||
} else {
|
||||
result = XWPrefs.getGCMDevID( m_context );
|
||||
if ( null != result ) {
|
||||
if ( result.equals("") ) {
|
||||
result = null;
|
||||
} else {
|
||||
typ = UtilCtxt.ID_TYPE_ANDROID_GCM;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue