android - xmpp in IntentService only works when debugging -



android - xmpp in IntentService only works when debugging -

when implementing xmpp on cloud connection server of google receive messages start wakefulbroadcastreceiver.

manifest.xml

<uses-permission android:name="android.permission.internet"/> <uses-permission android:name="android.permission.use_credentials"/> <uses-permission android:name="com.google.android.c2dm.permission.receive"/> <uses-permission android:name="android.permission.wake_lock"/> <permission android:name="com.tag.xmppandroid.permission.c2d_message" android:protectionlevel="signature"/> <uses-permission android:name="com.tag.xmppandroid.permission.c2d_message"/> <receiver android:name=".gcmbroadcastreceiver" android:permission="com.google.android.c2dm.permission.send"> <intent-filter> <action android:name="com.google.android.c2dm.intent.receive"/> <action android:name="com.google.android.c2dm.intent.registration"/> <category android:name="com.tag.xmppandroid"/> </intent-filter> </receiver> <service android:name=".gcmintentservice"></service>

wakefulbroadcastreceiver

public class gcmbroadcastreceiver extends wakefulbroadcastreceiver { @override public void onreceive(context context, intent intent) { // explicitly specify gcmintentservice handle intent. componentname comp = new componentname(context.getpackagename(), gcmintentservice.class.getname()); // start service, keeping device awake while launching. startwakefulservice(context, (intent.setcomponent(comp))); setresultcode(activity.result_ok); }

now wakefulbroadcastreceiver start intent service called gcmintentservice.class. purpose of intentservice receiving message , straight send message xmpp server send message. works, send message gcm.send(...) , server receives messages. but when im debugging.

the server won't receive message when application not in debugging mode. when application in debug mode send message xmpp server. looks thread shuts downwards , message not send server. when im debugging prevent service sleeping , has time send message or anything. know why happens?

code of intentservice:

@override protected void onhandleintent(intent intent) { bundle extras = intent.getextras(); final googlecloudmessaging gcm = googlecloudmessaging.getinstance(this); // getmessagetype() intent parameter must intent received // in broadcastreceiver. string messagetype = gcm.getmessagetype(intent); string message_id = null; string time_to_live = null; if (!extras.isempty()) // has effect of unparcelling bundle { if (googlecloudmessaging.message_type_send_error.equals(messagetype)) { sendnotification("send error: " + extras.tostring(), null); } else if (googlecloudmessaging.message_type_message.equals(messagetype)) { // values intent send on xmpp message_id = ((intent.getextras() == null) ? "empty bundle" : intent.getextras().getstring("message_id")); string message = ((intent.getextras() == null) ? "empty bundle" : intent.getextras().getstring("message")); time_to_live = ((intent.getextras() == null) ? "empty bundle" : intent.getextras().getstring("time_to_live")); bundle info = new bundle(); data.putstring("hello", "world"); data.putstring("delivered", "true"); seek { gcm.send(constants.gcm_sender_id + "@gcm.googleapis.com", message_id, constants.gcm_time_to_live, data); } grab (ioexception e) { e.printstacktrace(); } // send info view sendtoview(message_id, message, time_to_live); // show notification sendnotification("received: " + message, extras); // show toast on main thread handler mhandler = new handler(getmainlooper()); mhandler.post(new runnable() { @override public void run() { toast.maketext(getapplicationcontext(), constants.gcm_sender_id, toast.length_short).show(); } }); } } else { sendtoview("empty_bundle", null, null); } // release wake lock provided wakefulbroadcastreceiver. gcmbroadcastreceiver.completewakefulintent(intent); }

i hope can explain me why happens, or wrong since want understand why happens.

android xmpp google-cloud-messaging intentservice

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -