1. Are you ready for the Galaxy S20? Here is everything we know so far!

receiving Intents from running Service

Discussion in 'Android Development' started by v1nsai, May 15, 2010.

  1. v1nsai

    v1nsai Member
    Thread Starter

    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>
     



    1. Download the Forums for Android™ app!


      Download

       
Loading...

Share This Page

Loading...