• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps receiving Intents from running Service

v1nsai

Member
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:
package com.v1nsai.dataoff;

import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.net.wifi.WifiManager;
import android.os.IBinder;

public class WifiService extends Service
{
    /*public void onStartCommand( Intent intent, int startId )
    {
        WifiManager wm = (WifiManager)this.getSystemService(Context.WIFI_SERVICE);
    }*/
    @Override
    public IBinder onBind( Intent intent )
    {
        WifiManager wm = (WifiManager)this.getSystemService(Context.WIFI_SERVICE);
        
        if( intent.getAction() == "ACTION_SCREEN_ON")
            wm.setWifiEnabled(true);
        if( intent.getAction() == "ACTION_SCREEN_OFF")
            wm.setWifiEnabled(false);
        
        return null;
    }
}

and here's the service tag from AndroidManifest, contained in Application tag.
Code:
        <service    android:enabled="true"
                    android:exported="true"
                    android:name=".WifiService">
            <intent-filter>
                <action android:name="android.intent.action.SCREEN_OFF" />
                <action android:name="android.intent.action.SCREEN_ON" />
            </intent-filter>
        </service>
 
Back
Top Bottom