How to invite some friends using VK SDK in Xamarin.Android -
guys. i'm trying use vk api sdk in xamarin.android. create request:
var token = vkhelper.getvkusertoken(app.data.setting.list); var iparams = new dictionary<string, java.lang.object>(); iparams.add(vkapiconst.userid, vkbuffer.friend.id); iparams.add("type", "invite"); iparams.add("access_token", token); v = new vkrequest("apps.sendrequest", new vkparameters(iparams));
by clicking in button call executewithlistener:
v.executewithlistener(new reqvlist(new action(o => { runonuithread(() => { if (o.iscomplete) { try { showcustomalert(resource.drawable.checkmark, getstring(resource.string.sentinvite), android.graphics.color.argb(100, 0, 0, 200)); } catch { } } else { try { showcustomalert(resource.drawable.ic_post, getstring(resource.string.notsentinvite) + "\n" + getstring(o.messageid), android.graphics.color.argb(100, 200, 0, 0)); } catch { } } }); })));
listener:
public class reqvlist : vkrequest.vkrequestlistener { action<callbackvkresponse> complete; callbackvkresponse callbackvkresponse = new callbackvkresponse { iscomplete = false, messageid = 0 }; public reqvlist(action<callbackvkresponse> complete) { this.complete = complete; } public override void oncomplete(vkresponse p0) { base.oncomplete(p0); var response = p0.json.tostring(); callbackvkresponse.iscomplete = true; complete(callbackvkresponse); } public override void onerror(vkerror p0) { int errorcode = p0.apierror != null ? p0.apierror.errorcode : 0; callbackvkresponse.iscomplete = false; if (errorcode == 15) callbackvkresponse.messageid = resource.string.vkinviteerror; complete(callbackvkresponse); base.onerror(p0); } }
summary: if press invite friend, see "vkontakte" dialog window suggest message (here can accept or skip). if press "invite" friend has disabled invite him (or her) works fine. is:
....
else { try { showcustomalert(resource.drawable.ic_post, getstring(resource.string.notsentinvite) + "\n" + getstring(o.messageid), android.graphics.color.argb(100, 200, 0, 0)); } catch { } }
....
but if user has enabled invite him (or her) listener won't work , app freeze. in phone can press button , app unfreez , after can press again button - invite has worked fine. listener oncomplete works second time. is:
...
if (o.iscomplete) { try { showcustomalert(resource.drawable.checkmark, getstring(resource.string.sentinvite), android.graphics.color.argb(100, 0, 0, 200)); } catch { } }
...
help please.
Comments
Post a Comment