Coder Social home page Coder Social logo

gotev / android-host-monitor Goto Github PK

View Code? Open in Web Editor NEW
73.0 73.0 24.0 304 KB

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

Java 99.31% Shell 0.69%

android-host-monitor's People

Contributors

alexbbb avatar gotev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

android-host-monitor's Issues

Scope

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;

Crash at Gson adapter

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

Periodic reachability check not working

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

Network marked as reachable when it's not

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

  1. connecting to a host (VPN enabled)
  2. disabling VPN
  3. accessing the app again and getting

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.