How can I do that? I want service is run,when only wifi is active,when change is not.
When the app opens firstly,for there is not changed wifi connection,so app doesn't work.
I hope I could tell.
onReceive(..) in BroadcastReceiver class
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
ConnectivityManager conMan = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netInfo = conMan.getActiveNetworkInfo();
if (netInfo.isConnected()) {
Intent ServiceIntent = new Intent(context, BackService.class);
context.startService(ServiceIntent);
} else {
Intent ServiceIntent = new Intent(context, BackService.class);
context.stopService(ServiceIntent);
}
}
AndroidManifest.xml
<receiver android:name=".MyStartServiceReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.net.conn.CONNECTIVITY_CHANGE"/>
</intent-filter>
</receiver>
WiFi connection is changed to start more than one service can be.So it's a problem.How can I When wifi connection is active not a changed,background service is running?