mirror of
https://github.com/nextcloud/android.git
synced 2024-11-22 21:25:35 +03:00
Check internet connection on MainApp
Signed-off-by: alperozturk <alper_ozturk@proton.me>
This commit is contained in:
parent
9c21d8ef74
commit
e0776d8c37
2 changed files with 42 additions and 0 deletions
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* Nextcloud - Android Client
|
||||
*
|
||||
* SPDX-FileCopyrightText: 2024 Alper Ozturk <alper.ozturk@nextcloud.com>
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
package com.nextcloud.receiver
|
||||
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.net.ConnectivityManager
|
||||
import android.net.NetworkCapabilities
|
||||
import com.owncloud.android.MainApp
|
||||
|
||||
class NetworkChangeReceiver : BroadcastReceiver() {
|
||||
override fun onReceive(context: Context, intent: Intent?) {
|
||||
MainApp.setIsNetworkAvailable(isNetworkAvailable(context))
|
||||
}
|
||||
|
||||
private fun isNetworkAvailable(context: Context): Boolean {
|
||||
val connectivityManager = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
|
||||
val activeNetwork = connectivityManager.activeNetwork
|
||||
val networkCapabilities = connectivityManager.getNetworkCapabilities(activeNetwork)
|
||||
return networkCapabilities?.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET) == true
|
||||
}
|
||||
}
|
|
@ -31,6 +31,7 @@ import android.content.pm.ActivityInfo;
|
|||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.res.Resources;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
|
@ -59,6 +60,7 @@ import com.nextcloud.client.onboarding.OnboardingService;
|
|||
import com.nextcloud.client.preferences.AppPreferences;
|
||||
import com.nextcloud.client.preferences.AppPreferencesImpl;
|
||||
import com.nextcloud.client.preferences.DarkMode;
|
||||
import com.nextcloud.receiver.NetworkChangeReceiver;
|
||||
import com.nextcloud.utils.extensions.ContextExtensionsKt;
|
||||
import com.nmc.android.ui.LauncherActivity;
|
||||
import com.owncloud.android.authentication.AuthenticatorActivity;
|
||||
|
@ -204,6 +206,8 @@ public class MainApp extends Application implements HasAndroidInjector {
|
|||
|
||||
private static AppComponent appComponent;
|
||||
|
||||
private final NetworkChangeReceiver networkChangeReceiver = new NetworkChangeReceiver();
|
||||
|
||||
/**
|
||||
* Temporary hack
|
||||
*/
|
||||
|
@ -227,6 +231,15 @@ public class MainApp extends Application implements HasAndroidInjector {
|
|||
return powerManagementService;
|
||||
}
|
||||
|
||||
private void registerNetworkChangeReceiver() {
|
||||
IntentFilter filter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);
|
||||
registerReceiver(networkChangeReceiver, filter);
|
||||
}
|
||||
|
||||
public static void setIsNetworkAvailable(boolean isNetworkAvailable) {
|
||||
// TODO start pending operations if isNetworkAvailable
|
||||
}
|
||||
|
||||
private String getAppProcessName() {
|
||||
String processName = "";
|
||||
if(Build.VERSION.SDK_INT < Build.VERSION_CODES.P) {
|
||||
|
@ -375,6 +388,7 @@ public class MainApp extends Application implements HasAndroidInjector {
|
|||
}
|
||||
|
||||
registerGlobalPassCodeProtection();
|
||||
registerNetworkChangeReceiver();
|
||||
}
|
||||
|
||||
private final LifecycleEventObserver lifecycleEventObserver = ((lifecycleOwner, event) -> {
|
||||
|
|
Loading…
Reference in a new issue