receiving Intents from running Service


Last Updated:

  1. v1nsai

    v1nsai Well-Known Member This Topic's Starter

    Joined:
    Mar 24, 2010
    Messages:
    60
    Likes Received:
    3
    I'm having trouble figuring out how to catch Intents from my Service. I knew it was probably wrong, but I tried using onBind() to handle the Intents since it's the only Service method that receives Intents. It's not very long so I'm gonna post what I've got, can anyone see what I'm missing?

    Here's my service.java
    Code (Text):
    1. package com.v1nsai.dataoff;
    2.  
    3. import android.app.Service;
    4. import android.content.Context;
    5. import android.content.Intent;
    6. import android.net.wifi.WifiManager;
    7. import android.os.IBinder;
    8.  
    9. public class WifiService extends Service
    10. {
    11.     /*public void onStartCommand( Intent intent, int startId )
    12.     {
    13.         WifiManager wm = (WifiManager)this.getSystemService(Context.WIFI_SERVICE);
    14.     }*/
    15.     @Override
    16.     public IBinder onBind( Intent intent )
    17.     {
    18.         WifiManager wm = (WifiManager)this.getSystemService(Context.WIFI_SERVICE);
    19.        
    20.         if( intent.getAction() == "ACTION_SCREEN_ON")
    21.             wm.setWifiEnabled(true);
    22.         if( intent.getAction() == "ACTION_SCREEN_OFF")
    23.             wm.setWifiEnabled(false);
    24.        
    25.         return null;
    26.     }
    27. }
    28.  
    and here's the service tag from AndroidManifest, contained in Application tag.
    Code (Text):
    1.         <service    android:enabled="true"
    2.                     android:exported="true"
    3.                     android:name=".WifiService">
    4.             <intent-filter>
    5.                 <action android:name="android.intent.action.SCREEN_OFF" />
    6.                 <action android:name="android.intent.action.SCREEN_ON" />
    7.             </intent-filter>
    8.         </service>
     

    Advertisement

Share This Page

Loading...