pushSharp in vb.net for android -
i follow wiki of pushsharp project , write code send notification device.
imports pushsharp imports pushsharp.android imports pushsharp.core module module1 sub main() console.writeline("start notification : ") dim push new pushbroker() addhandler push.ondevicesubscriptionexpired, addressof devicesubscriptionchanged addhandler push.onchannelexception, addressof channelexception addhandler push.onserviceexception, addressof serviceexception addhandler push.onnotificationfailed, addressof notificationfailed addhandler push.ondevicesubscriptionexpired, addressof devicesubscriptionexpired addhandler push.ondevicesubscriptionchanged, addressof devicesubscriptionchanged addhandler push.onchannelcreated, addressof channelcreated addhandler push.onchanneldestroyed, addressof channeldestroyed push.registergcmservice(new gcmpushchannelsettings("aizasyccynj2q8bhjqj-gfr6n3cftm_vjpv9lie")) push.queuenotification(new gcmnotification().fordeviceregistrationid("apa91bgpd7et7_meqnl5d23bxihl3-4jkpfgpky_2a2mnijhfyeqhsm0ifvmrortng_394vjsxqyup0vbpbtqcwl-3ab_4mp-run4ypfkntqxfgurbexoc6m5j25ewuclxuhezhv5yulqzpijwoolhyfn28yx8ijrta5jup4lkybo7uvobsslzs").withjson("{""alert"":""hello world2!"",""badge"":6,""sound"":""sound.caf""}")) console.writeline("waiting queue finish...") 'stop , wait queues drains push.stopallservices(true) console.writeline("queue finished, press return exit...") console.readline() end sub sub devicesubscriptionchanged(sender object, oldsubscriptionid string, newsubscriptionid string, notification inotification) 'currently event ever happen android gcm console.writeline("device registration changed: old-> " & oldsubscriptionid & " new-> " & newsubscriptionid & " -> " & convert.tostring(notification)) end sub sub notificationsent(sender object, notification inotification) console.writeline("sent: " & convert.tostring(sender) & " -> " & convert.tostring(notification)) end sub sub notificationfailed(sender object, notification inotification, notificationfailureexception exception) console.writeline("failure: " & convert.tostring(sender) & " -> " & convert.tostring(notificationfailureexception.message) & " -> " & convert.tostring(notification)) end sub sub channelexception(sender object, channel ipushchannel, exception exception) console.writeline("channel exception: " & convert.tostring(sender) & " -> " & convert.tostring(exception)) end sub sub serviceexception(sender object, exception exception) console.writeline("channel exception: " & convert.tostring(sender) & " -> " & convert.tostring(exception)) end sub sub devicesubscriptionexpired(sender object, expireddevicesubscriptionid string, timestamp datetime, notification inotification) console.writeline("device subscription expired: " & convert.tostring(sender) & " -> " & expireddevicesubscriptionid) end sub sub channeldestroyed(sender object) console.writeline("channel destroyed for: " & convert.tostring(sender)) end sub sub channelcreated(sender object, pushchannel ipushchannel) console.writeline("channel created for: " & convert.tostring(sender)) end sub end module
i have api key , registration id phonegap plugin. have test api key , registration id little npm module send notification. when lunch code, nothing appened (no event match) , no notification on phone.
plz me need code.
i have suggestion. in android gcmintentservice class onhandleintent method log.d figure out notification reaching @ android end or not. sometime our code show notification not working , confused on side problem occurring. have implemented push notification using c# pushsharp , face same problem. error gcmintentservice, sendnotification code @ android side. working gcmintentservice class: /* * copyright (c) 2013 android open source project * * licensed under apache license, version 2.0 (the "license"); * may not use file except in compliance license. * may obtain copy of license @ * * http://www.apache.org/licenses/license-2.0 * * unless required applicable law or agreed in writing, software * distributed under license distributed on "as is" basis, * without warranties or conditions of kind, either express or implied. * see license specific language governing permissions , * limitations under license. */ package com.app.burnhelp.service; import java.util.date; import android.app.intentservice; import android.app.notificationmanager; import android.app.pendingintent; import android.content.context; import android.content.intent; import android.media.ringtonemanager; import android.os.bundle; import android.os.systemclock; import android.support.v4.app.notificationcompat; import android.util.log; import com.app.burnhelp.r; import com.app.burnhelp.r.color; import com.app.burnhelp.main.activity.loginactivity; import com.app.burnhelp.receiver.gcmbroadcastreceiver; import com.google.android.gms.gcm.googlecloudmessaging; /** * {@code intentservice} actual handling of gcm message. * {@code gcmbroadcastreceiver} (a {@code wakefulbroadcastreceiver}) holds * partial wake lock service while service work. when * service finished, calls {@code completewakefulintent()} release * wake lock. */ public class gcmintentservice extends intentservice { public static final int notification_id = 1; private notificationmanager mnotificationmanager; notificationcompat.builder builder; private string tag = "gcmintentservice"; public gcmintentservice() { super("gcmintentservice"); } @override protected void onhandleintent(intent intent) { bundle extras = intent.getextras(); googlecloudmessaging gcm = googlecloudmessaging.getinstance(this); // getmessagetype() intent parameter must intent received // in broadcastreceiver. string messagetype = gcm.getmessagetype(intent); if (!extras.isempty()) { // has effect of unparcelling bundle /* * filter messages based on message type. since gcm * extended in future new message types, ignore * message types you're not interested in, or don't * recognize. */ if (googlecloudmessaging. message_type_send_error.equals(messagetype)) { sendnotification("send error: " + extras.tostring()); } else if (googlecloudmessaging. message_type_deleted.equals(messagetype)) { sendnotification("deleted messages on server: " + extras.tostring()); // if it's regular gcm message, work. } else if (googlecloudmessaging. message_type_message.equals(messagetype)) { log.i(tag, "working... "); date cal = new date(); log.d("started at","started work on"+cal.gethours()+":"+cal.getminutes()+":"+cal.getseconds()); log.i(tag, "completed work @ " + systemclock.elapsedrealtime()); cal = new date(); log.d("end at","end work on"+cal.gethours()+":"+cal.getminutes()+":"+cal.getseconds()); // post notification of received message. sendnotification("" + extras.getstring("collapse_key")); cal = new date(); log.d("done at","done work on"+cal.gethours()+":"+cal.getminutes()+":"+cal.getseconds()); log.i(tag, "msg: " + extras.getstring("msg")); log.i(tag, "collapse_key: " + extras.getstring("collapse_key")); log.i(tag, "received: " + extras); } } // release wake lock provided wakefulbroadcastreceiver. gcmbroadcastreceiver.completewakefulintent(intent); } // put message notification , post it. // 1 simple example of might choose // gcm message. private void sendnotification(string msg) { mnotificationmanager = (notificationmanager) this.getsystemservice(context.notification_service); pendingintent contentintent = pendingintent.getactivity(this, 0, new intent(this, loginactivity.class), 0); notificationcompat.builder mbuilder = new notificationcompat.builder(this) .setsmallicon(r.drawable.bhiogo) .setcontenttitle("burnhelp") .setstyle(new notificationcompat.bigtextstyle() .bigtext(msg)) .setcontenttext(msg); //vibration , sound mbuilder.setvibrate(new long[] { 1000, 1000, 1000, 1000, 1000 }); mbuilder.setsound(ringtonemanager.getdefaulturi(ringtonemanager.type_notification)); //led mbuilder.setlights(color.sky_blue_1, 3000, 3000); // mbuilder.defaults = notification.default_lights | notification.default_vibrate; // toast.maketext(getapplicationcontext(), "new message: " + msg, toast.length_long).show(); mbuilder.setcontentintent(contentintent); mnotificationmanager.notify(notification_id, mbuilder.build()); } }
Comments
Post a Comment