java - GCM onHandleIntent(Intent intent) not being called -
my onhandleintent(intent intent) function in gcmintentservice
has registration gcm
call variable function sends gcm token back-end db. while run mainactivity
constructor of gcmintentservice
gets called while onhandleintent doesnt. gcmintentservice
.
public class gcmintentservice extends intentservice { private static final string tag = "regintentservice"; private static final string[] topics = {"global"}; string senderid = "1048700326431"; asynchttpclient client = new asynchttpclient(); public gcmintentservice() { super(tag); log.i(tag, "always in here"); } @override public void onhandleintent(intent intent) { log.i(tag, " need in here"); sharedpreferences sharedpreferences = preferencemanager.getdefaultsharedpreferences(this); try { // [start register_for_gcm] // call goes out network retrieve token, subsequent calls // local. // [start get_token] instanceid instanceid = instanceid.getinstance(this); string token = instanceid.gettoken(senderid, googlecloudmessaging.instance_id_scope, null); // [end get_token] log.i(tag, "gcm registration token: " + token); // todo: implement method send registration app's servers. sendregistrationtoserver(token); // subscribe topic channels subscribetopics(token); // should store boolean indicates whether generated token has been // sent server. if boolean false, send token server, // otherwise server should have received token. sharedpreferences.edit().putboolean(quickstartpreferences.sent_token_to_server, true).apply(); // [end register_for_gcm] } catch (exception e) { log.d(tag, "failed complete token refresh", e); // if exception happens while fetching new token or updating our registration data // on third-party server, ensures we'll attempt update @ later time. sharedpreferences.edit().putboolean(quickstartpreferences.sent_token_to_server, false).apply(); } // notify ui registration has completed, progress indicator can hidden. intent registrationcomplete = new intent(quickstartpreferences.registration_complete); localbroadcastmanager.getinstance(this).sendbroadcast(registrationcomplete); } /** * persist registration third-party servers. * * modify method associate user's gcm registration token server-side account * maintained application. * * @param token new token. */ private void sendregistrationtoserver(string token) { final requestparams params = new requestparams(); params.put("id", token); client.post("", params, new jsonhttpresponsehandler() { @override public void onstart() { // called before request started } public void onsuccess(int statuscode, preferenceactivity.header[] headers, jsonobject response) { } public void onfailure(int statuscode, preferenceactivity.header[] headers, jsonobject errorresponse, throwable e) { // called when response http status "4xx" (eg. 401, 403, 404) } @override public void onretry(int retryno) { // called when request retried } }); } /** * subscribe gcm topics of interest, defined topics constant. * * @param token gcm token * @throws ioexception if unable reach gcm pubsub service */ // [start subscribe_topics] private void subscribetopics(string token) throws ioexception { (string topic : topics) { gcmpubsub pubsub = gcmpubsub.getinstance(this); pubsub.subscribe(token, "/topics/" + topic, null); } } }
i had same issue solved adding manifest:
<service android:name="com.futec.h2o.registrationintentservice" android:exported="false" > <intent-filter> <action android:name="com.google.android.c2dm.intent.registration" /> </intent-filter> </service>
Comments
Post a Comment