Skip to content

Commit 2c7f873

Browse files
author
Dev15
committed
Kamran Ahmed khan
1 parent fe14adc commit 2c7f873

File tree

16 files changed

+160
-7
lines changed

16 files changed

+160
-7
lines changed

.idea/gradle.xml

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/other.xml

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

InternetCheckerlibrary/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
plugins {
2+
alias(libs.plugins.android.library)
3+
alias(libs.plugins.jetbrains.kotlin.android)
4+
}
5+
6+
android {
7+
namespace = "com.internetcheckerlibrary"
8+
compileSdk = 34
9+
10+
defaultConfig {
11+
minSdk = 24
12+
13+
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
14+
consumerProguardFiles("consumer-rules.pro")
15+
}
16+
17+
buildTypes {
18+
release {
19+
isMinifyEnabled = false
20+
proguardFiles(
21+
getDefaultProguardFile("proguard-android-optimize.txt"),
22+
"proguard-rules.pro"
23+
)
24+
}
25+
}
26+
compileOptions {
27+
sourceCompatibility = JavaVersion.VERSION_1_8
28+
targetCompatibility = JavaVersion.VERSION_1_8
29+
}
30+
kotlinOptions {
31+
jvmTarget = "1.8"
32+
}
33+
}
34+
35+
dependencies {
36+
37+
implementation(libs.androidx.core.ktx)
38+
implementation(libs.androidx.appcompat)
39+
implementation(libs.material)
40+
testImplementation(libs.junit)
41+
androidTestImplementation(libs.androidx.junit)
42+
androidTestImplementation(libs.androidx.espresso.core)
43+
}

InternetCheckerlibrary/consumer-rules.pro

Whitespace-only changes.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.internetcheckerlibrary
2+
3+
import androidx.test.platform.app.InstrumentationRegistry
4+
import androidx.test.ext.junit.runners.AndroidJUnit4
5+
6+
import org.junit.Test
7+
import org.junit.runner.RunWith
8+
9+
import org.junit.Assert.*
10+
11+
/**
12+
* Instrumented test, which will execute on an Android device.
13+
*
14+
* See [testing documentation](http://d.android.com/tools/testing).
15+
*/
16+
@RunWith(AndroidJUnit4::class)
17+
class ExampleInstrumentedTest {
18+
@Test
19+
fun useAppContext() {
20+
// Context of the app under test.
21+
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
22+
assertEquals("com.internetcheckerlibrary.test", appContext.packageName)
23+
}
24+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
3+
4+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
5+
</manifest>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.internetcheckerlibrary
2+
import android.content.Context
3+
import android.net.ConnectivityManager
4+
import android.net.NetworkCapabilities
5+
import android.os.Build
6+
7+
object InternetChecker {
8+
9+
fun isInternetAvailable(context: Context): Boolean {
10+
val connectivityManager = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
11+
val network = connectivityManager.activeNetwork ?: return false
12+
val capabilities = connectivityManager.getNetworkCapabilities(network) ?: return false
13+
return when {
14+
capabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI) -> true
15+
capabilities.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR) -> true
16+
capabilities.hasTransport(NetworkCapabilities.TRANSPORT_ETHERNET) -> true
17+
else -> false
18+
}
19+
}
20+
}

0 commit comments

Comments
 (0)