Issue
I have an app with a webview
. My site allows registration and login. If the user installs the app for the first time, the app will register the device for GCM
. However, when they actually login to the site, the gcm_id is not sent to the server because I have it attached to the webView.load_url
as a parameter which is only ran when you first start the app.
How do you reload or send the gcm_id without having to wait for them to run the app a 2nd time? I don't want it to be continuous either where it appends a url on every page load if I can help it. I've seen other examples but none have help my issue. BTW my server runs php if that matters.
Solution
I found a very nice class that will send http get requests including authentication if you need it via http or https with two lines of code.
Very easy to use and you can use it like so.
EasyHttpClient client = new EasyHttpClient();
System.out.println(client.get("https://encrypted.google.com/"));
So what I came up with is when they first launch the app there will be a flag set when the device is initially registered. Then as long as that flag is set, it will periodically send a request using this http client to register it and if successfull it will null the flag and not try anymore. Since that flag is only set if the registration ID has not been created yet, it will never be set again unless they uninstall it of course. Seems good so far. I have to do this because until they login they are anonymous and my site can't register anonymous users. Just thought someone else might like to know as I found all kinds of tedious ways but that EasyHttpClient is the best I've found.
BTW The reason I did this is because what if they use the app once and get a message after that, the push notification wont work so I had to get it to register with my server the first time they use it.
Answered By - Panama Jack
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.