Fixed service being started when it should be disabled.
This commit is contained in:
parent
39a2120300
commit
ac12941ea8
3 changed files with 8 additions and 10 deletions
|
@ -62,12 +62,6 @@
|
|||
|
||||
<service android:name=".service.ChatService" />
|
||||
|
||||
<receiver android:name=".util.NetworkChangedReceiver" >
|
||||
<intent-filter>
|
||||
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
|
|
|
@ -4,11 +4,12 @@ import java.io.File
|
|||
|
||||
import android.app.Service
|
||||
import android.bluetooth.BluetoothAdapter
|
||||
import android.content.{Context, Intent}
|
||||
import android.content.{Context, Intent, IntentFilter}
|
||||
import android.net.ConnectivityManager
|
||||
import android.os.Handler
|
||||
import com.nutomic.ensichat.bluetooth.BluetoothInterface
|
||||
import com.nutomic.ensichat.core.{ConnectionHandler, Crypto}
|
||||
import com.nutomic.ensichat.util.{Database, SettingsWrapper}
|
||||
import com.nutomic.ensichat.util.{Database, NetworkChangedReceiver, SettingsWrapper}
|
||||
|
||||
object ChatService {
|
||||
|
||||
|
@ -33,6 +34,8 @@ class ChatService extends Service {
|
|||
new ConnectionHandler(new SettingsWrapper(this), new Database(this), callbackHandler,
|
||||
ChatService.newCrypto(this))
|
||||
|
||||
private val networkReceiver = new NetworkChangedReceiver()
|
||||
|
||||
override def onBind(intent: Intent) = binder
|
||||
|
||||
override def onStartCommand(intent: Intent, flags: Int, startId: Int): Int = {
|
||||
|
@ -55,11 +58,13 @@ class ChatService extends Service {
|
|||
connectionHandler))
|
||||
}
|
||||
connectionHandler.start()
|
||||
registerReceiver(networkReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION))
|
||||
}
|
||||
|
||||
override def onDestroy(): Unit = {
|
||||
notificationHandler.cancelPersistentNotification()
|
||||
connectionHandler.stop()
|
||||
unregisterReceiver(networkReceiver)
|
||||
}
|
||||
|
||||
def getConnectionHandler = connectionHandler
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package com.nutomic.ensichat.util
|
||||
|
||||
import android.content.{Intent, Context, BroadcastReceiver}
|
||||
import android.net.ConnectivityManager
|
||||
import android.content.{BroadcastReceiver, Context, Intent}
|
||||
import com.nutomic.ensichat.service.ChatService
|
||||
|
||||
class NetworkChangedReceiver extends BroadcastReceiver {
|
||||
|
|
Reference in a new issue