android - Dynamically setting SENDER_ID in GCM -
i trying set project sender id dynamically fetching server throws invalid sender id exception. fetching sender id server in base application class make sure before application launches , have overrided getsenderids() method in gcmintentservice.
public gcmintentservice() { super(); } @override protected string[] getsenderids(context context) { string[] ids = new string[1]; ids[0] = sender_id; return ids; } but getting invalid sender id exception. i'd appreciate if 1 give me informed opinion on how set sender id dynammically server.
ok managed self. i'll try explain it. so, firstly edited getsenderids() method this:
@override protected string[] getsenderids(context context) { updatesenderidtask(context); string[] ids = new string[1]; ids[0] = getsenderid(context); return ids; } previously had set ids[0] variable sender_id set inside updatesenderidtask method. invalid sender id exception thrown because gcm access sender_id variable before updatesenderidtask method executed though had called inside base application class. so, called updatesendertask inside getsenderids overrided method make sure fetch id server before gcm uses it. double check it, set ids[0] local method getsenderid. here implementation it:
static string getsenderid(context context) { customsharedprefs prefs = customsharedprefs.getinstance(context); if (prefs.getstring(constants.sender_id).equals("0") || prefs.getstring(constants.sender_id) == null) { updatesenderidtask(context); } log.e("returned sender_id", prefs.getstring(constants.sender_id)); return prefs.getstring(constants.sender_id); } the updatesenderidtask method fetches id server , stores in shared preference variable.
Comments
Post a Comment