mirror of
https://github.com/Shabinder/SpotiFlyer.git
synced 2024-11-22 09:04:32 +01:00
Replace pinging google with spotify
This commit is contained in:
parent
48e4c04973
commit
ae96e37ba2
@ -31,6 +31,8 @@ import kotlinx.coroutines.withContext
|
|||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
import java.lang.Exception
|
import java.lang.Exception
|
||||||
import java.net.InetSocketAddress
|
import java.net.InetSocketAddress
|
||||||
|
import java.net.URL
|
||||||
|
import javax.net.ssl.HttpsURLConnection
|
||||||
|
|
||||||
const val TAG = "C-Manager"
|
const val TAG = "C-Manager"
|
||||||
|
|
||||||
@ -103,17 +105,16 @@ class ConnectionLiveData(context: Context) : LiveData<Boolean>() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a ping to googles primary DNS.
|
* Try Establishing an Actual Internet Connection.
|
||||||
* If successful, that means we have internet.
|
* If successful, that means we have internet.
|
||||||
*/
|
*/
|
||||||
object DoesNetworkHaveInternet {
|
object DoesNetworkHaveInternet {
|
||||||
suspend fun execute(network: Network): Boolean = withContext(Dispatchers.IO) {
|
suspend fun execute(network: Network): Boolean = withContext(Dispatchers.IO) {
|
||||||
try {
|
try {
|
||||||
Log.d(TAG, "PINGING google.")
|
val url = URL("https://open.spotify.com/")
|
||||||
val socket = network.socketFactory.createSocket() ?: throw IOException("Socket is null.")
|
val connection = network.openConnection(url) as HttpsURLConnection
|
||||||
socket.connect(InetSocketAddress("8.8.8.8", 53), 1500)
|
connection.connect()
|
||||||
socket.close()
|
connection.disconnect()
|
||||||
Log.d(TAG, "PING success.")
|
|
||||||
true
|
true
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
|
@ -41,7 +41,7 @@ expect val currentPlatform: AllPlatforms
|
|||||||
suspend fun isInternetAccessible(): Boolean {
|
suspend fun isInternetAccessible(): Boolean {
|
||||||
return withContext(dispatcherIO) {
|
return withContext(dispatcherIO) {
|
||||||
try {
|
try {
|
||||||
ktorHttpClient.head<String>("https://google.com")
|
ktorHttpClient.head<String>("https://open.spotify.com/")
|
||||||
true
|
true
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
|
Loading…
Reference in New Issue
Block a user