parent
9c27d982f7
commit
442d35414e
@ -0,0 +1,24 @@ |
||||
package com.frank.ffmpeg.handler |
||||
|
||||
import android.content.BroadcastReceiver |
||||
import android.content.Context |
||||
import android.content.Intent |
||||
import android.net.ConnectivityManager |
||||
import com.frank.ffmpeg.listener.OnNetworkChangeListener |
||||
|
||||
class ConnectionReceiver(networkChangeListener: OnNetworkChangeListener) : BroadcastReceiver() { |
||||
|
||||
var networkChangeListener :OnNetworkChangeListener ?= networkChangeListener |
||||
|
||||
override fun onReceive(context: Context?, intent: Intent?) { |
||||
|
||||
if (ConnectivityManager.CONNECTIVITY_ACTION == intent?.action) { |
||||
val connectivityManager : ConnectivityManager = context?.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager |
||||
val activeNetworkInfo = connectivityManager.activeNetworkInfo |
||||
if (activeNetworkInfo == null || !activeNetworkInfo.isAvailable) { |
||||
networkChangeListener?.onNetworkChange() |
||||
} |
||||
|
||||
} |
||||
} |
||||
} |
@ -0,0 +1,7 @@ |
||||
package com.frank.ffmpeg.listener |
||||
|
||||
interface OnNetworkChangeListener { |
||||
|
||||
fun onNetworkChange() |
||||
|
||||
} |
Loading…
Reference in new issue