wifiのステータスが変更されたときに通知するアプリをバックグラウンドで実行しようとしています。
public class BackgroundJobs extends Service {
public int onStartCommand(Intent intent, int flags, int startId) {
Log.i("BACKJOBS", "here we are");
wifiInfo wifiHandler = new wifiInfo(this);
// wifistatus checks if wifi is on or off, returning a boolean
if(wifiHandler.wifiStatus())
Log.i("BACKJOBS", "WIFI ON");
else
Log.i("BACKJOBS", "WIFI OFF");
return Service.START_NOT_STICKY;
}
@Override
public IBinder onBind(Intent intent) {
//TODO for communication return IBinder implementation
return null;
}
}
MainActivity では、次のようにサービスを開始します。
startService(new Intent(this, BackgroundJobs.class));
および AndroidManifest.xml で:
<service android:name=".gestioneServizi.BackgroundJobs"/>
アプリを起動し、ホーム ボタンを押して自宅に戻り、Wi-Fi をオンまたはオフに切り替えましたが、ログ "BACKJOBS" が表示されません。
私は何かを誤解していますか、それとも間違った方法で作業していますか?