@@ -0,0 +1,2164 @@
+package xyz.fitraditya.androidmqtt;%0A%0Aimport android.content.BroadcastReceiver;%0Aimport android.content.Context;%0Aimport android.content.Intent;%0Aimport android.content.SharedPreferences;%0Aimport android.net.ConnectivityManager;%0Aimport android.net.NetworkInfo;%0A%0Apublic class NetWatcher extends BroadcastReceiver %7B%0A%0A    public static final String DEBUG_TAG = %22MqttService%22;%0A    private static final String ACTION_FORCE_RECONNECT = DEBUG_TAG + %22.FORCE_RECONNECT%22;%0A    private static String PREFS = %22mqtt-prefs%22;%0A    private static String sHOSTNAME = %22-Hostname%22;%0A%0A    @Override%0A    public void onReceive(Context context, Intent intent) %7B%0A        final SharedPreferences sharedPref = context.getSharedPreferences(PREFS, Context.MODE_PRIVATE);%0A        String vHostname;%0A        vHostname = sharedPref.getString(sHOSTNAME, %22%22);%0A        final ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);%0A%0A        if (connectivityManager != null) %7B%0A            final NetworkInfo netInfo = connectivityManager.getActiveNetworkInfo();%0A%0A            if (netInfo != null && netInfo.getState() == NetworkInfo.State.CONNECTED) %7B%0A                if (vHostname.length() %3E 0) %7B%0A                    while (!isAvailable(vHostname)) %7B%0A                        try %7B%0A                            Thread.sleep(2000);%0A                        %7D catch (InterruptedException e) %7B%0A                            e.printStackTrace();%0A                        %7D%0A                    %7D%0A%0A                    intent = new Intent(context, MQTTService.class);%0A                    intent.setAction(ACTION_FORCE_RECONNECT);%0A                    context.startService(intent);%0A                %7D%0A            %7D%0A        %7D%0A    %7D%0A%0A    public Boolean isAvailable(String vHostname) %7B%0A        try %7B%0A            Process p1 = java.lang.Runtime.getRuntime().exec(%22ping -c 1 %22 + vHostname);%0A            int returnVal = p1.waitFor();%0A            boolean reachable = (returnVal == 0);%0A%0A            if (reachable) %7B%0A                return reachable;%0A            %7D%0A        %7D catch (Exception e) %7B%0A            e.printStackTrace();%0A        %7D%0A%0A        return false;%0A    %7D%0A%0A%7D%0A

Add NetWatcher class