Wednesday, 15 February 2012

broadcast - How to make my service run? -


I want to start a service when the power is connected to my device and displays a notification but my app does nothing Please help me, I'm new to the Android world, maybe I'm missing something, the following is the mile code:

My manifest:

< P>
  & lt; Receiver Android: name = "com.tlm.grhs_client.WiFiMonitor" & gt; & Lt; Intent-Filter & gt; & Lt; Action Android: name = "android.intent.action.ACTION_POWER_CONNECTED" /> & Lt; / Intent-Filter & gt;  

  Public class broadcasts WiFiMonter broadcaster receivers {@ Override public Wii on receipt (reference reference, intended intent) {Connectivity Manager cm = (Connectivity Manager) context.getSystemService (context. CONNECTIVITY_SERVICE); Network Info Info = CmsActactNetworkInfo (); If (info! = Null & amp; info.getType () == connectivity manager. TYPE_WIFI) {if (info.isConnected ()) {// iniciar servicio intent service current = new intent (reference, ClientService.class); Context.startService (serviceIntent); } Else {// parar servicio intent serviceless = new intent (reference, client service). Context.stopService (serviceIntent); }}}}  

and my service class is:

  public class client service delivery service {@IVERRIDE PUBLIC IBINABADER ON BIND (Intent Intent) {new unsupported operation exception ("not yet implemented"); } @ Override Public Wide On Creativity (Toast) Maketext (this, "service fu crado", toast. LNGGLOG). Show (); } @TargetApi (Build.VERSION_CODES.JELLY_BEAN) @SuppressLint ("NewApi") @ Start overwrite public on {start intent, int start iad} {// your long lasting tasks here. Toast. Make Text (this, "Service InDido", Toast. LNNHHLoad) Show (); Notification. Builder Notifier = New Notification. Builder (this); NotiBuilder.setContentTitle ("Prueba"); NotiBuilder.setContentText ("Esto es una prueba"); Notification Notification = notiBuilder.build (); Notification Manager Manager = (Notification Manager) this.getSystemService (this.NOTIFICATION_SERVICE); Manager.notify (1, Notification); } @ Override Public Empty on Destiny () {Toast. Make Text (this, "Service Distro", Toast. LNNHHLOG). Show (); }}  

I turn on WiFi and establish a connection but do not show the notification.

In this way, for Android notifications, some text is required according to a title and some documents < / P>

Add an icon but otherwise the code (at a quick glance) looks like this should work.


No comments:

Post a Comment