This example is based on the user's existing Android project human flesh translation, in Xamarin replaced and modified many methods of naming, such as some attributes need to remove the getname get prefix, some method names need to replace Java's camel naming specification by using Pascal nomenclature
There are also some differences in the way internal classes are used, but on the whole, most of the method names are consistent with the Java original Android, so it's easy to switch to Xamarin if you have an existing Android project. 66 likes in Xamarin
Reference Java version: http://blog.csdn.net/wxdjaqgs/article/details/44561101
Bo Master provides source code download
All I have to do is stick the picture file I need. and start translating the code.
Since the packaging process for iOS has not yet been studied, the test did not use iOS testing. There's time to make up for it later.
PS: No comments on the entire (don't ask me, I won't say anything to kill--!)
Post code:
usingSystem;usingAndroid.app;usingandroid.content;usingAndroid.widget;usingAndroid.os;namespaceapp3{[Activity (Label="APP3", Mainlauncher =true, Icon ="@drawable/icon")] Public classmainactivity:activity { Public StaticString action_btn ="Com.example.notification.btn.login"; Public StaticString Intent_name ="Btnid"; Public Const intIntent_btn_login =1; StaticNotificationbroadcastreceiver Mreceiver; Public StaticNotificationmanager Notifymanager; protected Override voidOnCreate (Bundle bundle) {Base. OnCreate (bundle); //Set Our view from the "main" layout resourceSetcontentview (Resource.Layout.Main); Button Button=(Button) Findviewbyid (Resource.Id.btn_notification); button. Click+ = (sender, e) = ={notification ();}; } Private voidIntireceiver () {Mreceiver=NewNotificationbroadcastreceiver (); Intentfilter Intentfilter=NewIntentfilter (); Intentfilter.addaction (ACTION_BTN); Applicationcontext.registerreceiver (Mreceiver, Intentfilter); } Public voidUnregeisterreceiver () {if(Mreceiver! =NULL) {applicationcontext.unregisterreceiver (mreceiver); Mreceiver=NULL; } } Private voidnotification () {unregeisterreceiver (); Intireceiver (); Remoteviews remoteviews=Newremoteviews (PackageName, Resource.Layout.notification); Remoteviews.settextviewtext (RESOURCE.ID.TV_UP,"Airport Boutique Wireless"); Remoteviews.settextviewtext (Resource.Id.tv_down,"Free Access"); Intent Intent=NewIntent (ACTION_BTN); Intent. PutExtra (Intent_name, Intent_btn_login); Pendingintent INTENTPI= Pendingintent.getbroadcast ( This,1, intent, pendingintentflags.updatecurrent); Remoteviews.setonclickpendingintent (Resource.Id.btn_login, INTENTPI); Intent Intent2=NewIntent (); Intent2. SetClass ( This,typeof(mainactivity)); Intent2. SetFlags (Activityflags.newtask|activityflags.cleartask); Pendingintent intentcontent= Pendingintent.getactivity ( This,0, Intent2, pendingintentflags.updatecurrent); Notification.builder Builder=NewNotification.builder ( This); Builder. Setongoing (false); Builder. Setautocancel (false); Builder. SetContent (remoteviews); Builder. Setticker ("is using the airport wireless"); Builder. Setsmallicon (Resource.Drawable.id_airport); Notification Notification=Builder. Build (); Notification. Defaults=Notificationdefaults.sound; Notification. Flags=notificationflags.noclear; Notification. Contentintent=intentcontent; Notifymanager=(Notificationmanager) Getsystemservice (Context.notificationservice); Notificationmanager Notificationmanager=Notifymanager; Notificationmanager.notify (0, notification); } classNotificationbroadcastreceiver:broadcastreceiver { Public Override voidOnReceive (Context context, Intent Intent) {String action=Intent. Action; if(action. Equals (ACTION_BTN)) {intbtn_id = Intent. Getintextra (Intent_name,0); Switch(btn_id) { CaseINTENT_BTN_LOGIN:Toast.MakeText (Context,"log in from the notification bar point", Toastlength.short). Show (); if(Mreceiver! =NULL) {context. Applicationcontext.unregisterreceiver (Mreceiver); Mreceiver=NULL; } Notificationmanager Notificationmanager=Notifymanager; Notificationmanager.cancel (0); Break; } } } } }}
Xamarin Mini try Sledgehammer notification bar message notification and button (based on Java code human flesh conversion)