gotev / android-host-monitor Goto Github PK
View Code? Open in Web Editor NEWEasily monitor device network state and remote hosts reachability on Android
Home Page: http://gotev.github.io/android-host-monitor/
License: Apache License 2.0
Easily monitor device network state and remote hosts reachability on Android
Home Page: http://gotev.github.io/android-host-monitor/
License: Apache License 2.0
onHostStatusChanged реагирует тока на отсутствие сети... при переключение на wifi или mobile не реагирует.
Hi,
If I I use initialize the monitor in an activity using broadcastreceiver( init in manifest), will the broadcast be still fired when the activity is destroyed?
And what if I use Application as context?
Thanks;
Fatal Exception: java.lang.AssertionError: Missing field in net.gotev.hostmonitor.a
at com.google.gson.internal.bind.TypeAdapters$EnumTypeAdapter.(SourceFile)
at com.google.gson.internal.bind.TypeAdapters$30.create(SourceFile:838)
at com.google.gson.Gson.getAdapter(SourceFile:416)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getFieldAdapter(SourceFile:135)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.(SourceFile)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(SourceFile:104)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(SourceFile:160)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(SourceFile:96)
at com.google.gson.Gson.getAdapter(SourceFile:416)
at com.google.gson.internal.bind.MapTypeAdapterFactory.create(SourceFile:126)
at com.google.gson.Gson.getAdapter(SourceFile:416)
at com.google.gson.Gson.fromJson(SourceFile:878)
at com.google.gson.Gson.fromJson(SourceFile:844)
at com.google.gson.Gson.fromJson(SourceFile:793)
at net.gotev.hostmonitor.HostMonitorConfig.getHostsMap(SourceFile:74)
at net.gotev.hostmonitor.HostMonitor.onHandleIntent(SourceFile:83)
at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:157)
at android.os.HandlerThread.run(HandlerThread.java:61)
Caused by java.lang.NoSuchFieldException: NONE
at java.lang.Class.getField(Class.java:724)
at com.google.gson.internal.bind.TypeAdapters$EnumTypeAdapter.(SourceFile)
at com.google.gson.internal.bind.TypeAdapters$30.create(SourceFile:838)
at com.google.gson.Gson.getAdapter(SourceFile:416)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getFieldAdapter(SourceFile:135)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.(SourceFile)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(SourceFile:104)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(SourceFile:160)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(SourceFile:96)
at com.google.gson.Gson.getAdapter(SourceFile:416)
at com.google.gson.internal.bind.MapTypeAdapterFactory.create(SourceFile:126)
at com.google.gson.Gson.getAdapter(SourceFile:416)
at com.google.gson.Gson.fromJson(SourceFile:878)
at com.google.gson.Gson.fromJson(SourceFile:844)
at com.google.gson.Gson.fromJson(SourceFile:793)
at net.gotev.hostmonitor.HostMonitorConfig.getHostsMap(SourceFile:74)
at net.gotev.hostmonitor.HostMonitor.onHandleIntent(SourceFile:83)
at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:157)
at android.os.HandlerThread.run(HandlerThread.java:61)
Strange crash, how to fix it? Tried to add -keep class net.gotev.* in my proguard rules, but not hepled
Is there any simple solution to trigger a rechability test already right after the HostMonitorConfig initialization?
Hi @gotev
I would like to know if there is something wrong with this configuration. I don't get periodic reachability checks, reachability is checked only the first time Activity
is shown.
I'm using the extended okhttp3 reachability at https://github.com/nicolabeghin/android-host-monitor but this happened using the "stock" version of the library too.
Maybe your library checks for reachability only when Android notifies/broadcast some kind of network change?
import net.gotev.hostmonitor.HostMonitorBroadcastReceiver;
import net.gotev.hostmonitor.HostMonitorConfig;
import net.gotev.hostmonitor.HostStatus;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
/**
* Created by nbeghin on 03/06/2015.
*/
public abstract class AbstractBaseActivity extends AppCompatActivity {
public HostMonitorBroadcastReceiver receiver;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
receiver = new HostMonitorBroadcastReceiver() {
@Override
public void onHostStatusChanged(HostStatus status) {
Log.i("INTERNAL HostMonitor", status.toString());
Toast.makeText(AbstractBaseActivity.this, "CRM "+(status.isReachable()==false?"non":"")+" raggiungibile", Toast.LENGTH_SHORT).show();
if (status.isReachable()!=status.isPreviousReachable()) {
Toast.makeText(AbstractBaseActivity.this, "CRM "+(status.isReachable()==false?"non":"")+" raggiungibile", Toast.LENGTH_SHORT).show();
} else {
}
}
@Override
public void onReceive(Context context, Intent intent) {
super.onReceive(context, intent);
Log.i("INTERNAL HostMonitor", "onReceive");
}
};
HostMonitorConfig.reset(this);
new HostMonitorConfig(this)
.setBroadcastAction(getString(R.string.broadcast_action_network_host_monitor))
.setCheckIntervalInSeconds(10)
.add(Constants.HOST, Integer.parseInt(Constants.PORT))
.setSocketTimeoutInMilliseconds(1000)
.save();
Log.w(MainActivity.AppName, getClass().getName() + " onCreate");
}
@Override
protected void onResume() {
super.onResume();
receiver.register(this);
Log.w(MainActivity.AppName, getClass().getName() + " onResume");
}
@Override
protected void onStart() {
super.onStart();
Log.w(MainActivity.AppName, getClass().getName() + " onStart");
}
@Override
protected void onStop() {
super.onStop();
Log.w(MainActivity.AppName, getClass().getName() + " onStop");
}
@Override
protected void onPause() {
super.onPause();
receiver.unregister(this);
Log.w(MainActivity.AppName, getClass().getName() + " onPause");
}
}
03-29 18:53:24.058 23055-23055/testapp D/HostMonitor: reset configuration
03-29 18:53:24.086 23055-23055/testapp D/HostMonitor: cancelling scheduled checks
03-29 18:53:24.086 23055-23055/testapp D/HostMonitorConfig: saving configuration
03-29 18:53:24.130 23055-23055/testapp D/HostMonitor: cancelling scheduled checks
03-29 18:53:24.130 23055-23055/testapp D/HostMonitorConfig: scheduling periodic checks every 10 seconds
03-29 18:53:24.130 23055-23055/testapp D/HostMonitorConfig: triggering reachability check
03-29 18:53:24.658 23055-23100/testapp D/HostMonitor: Starting reachability check
03-29 18:53:24.862 23055-23100/testapp D/HostMonitor: Host 10.10.22.15 is currently reachable on port 8021 via WIFI
03-29 18:53:24.866 23055-23100/testapp D/HostMonitor: Broadcast with action: com.altevie.bocconi.deskapp.prd and status: {"connectionType":"WIFI","host":"10.10.22.15","previousConnectionType":"NONE","port":8021,"previousReachable":true,"reachable":true}
03-29 18:53:24.866 23055-23100/testapp D/HostMonitorConfig: saving hosts status map
03-29 18:53:24.870 23055-23100/testapp D/HostMonitor: Reachability check finished!
03-29 18:53:25.694 23055-23055/testapp I/INTERNAL HostMonitor: {"connectionType":"WIFI","host":"10.10.22.15","previousConnectionType":"NONE","port":8021,"previousReachable":true,"reachable":true}
03-29 18:53:25.706 23055-23055/testapp I/INTERNAL HostMonitor: onReceive
Just to confirm as it should be standard/unfixed Android behavior: if you connect to a host then this becomes unresponsive (es. VPN is interrupted) your library still marks it as "reachable". I just tested it in genymotion by
03-22 12:53:27.489 5612-5612/MyApp I/HostMonitor: {"connectionType":"WIFI","host":"10.10.22.15","port":8021,"previousConnectionType":"NONE","previousReachable":true,"reachable":true}
It seems like it's not fixable: ref. issue #82 of ksoap2
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.