+ /**
+ * Gets the server URL according to the user preferences.
+ *
+ * @param context Context instance
+ * @param path URL path
+ * @return the server URL
+ * @throws MalformedURLException if the user preferences create an invalid URL
+ */
+ public static URL getServerURL(final Context context, final String path) throws MalformedURLException{
+ final String hostname=PreferenceManager.getDefaultSharedPreferences(context).getString("hostname", "fonbot.ieval.ro");
+ final int port=Integer.parseInt(PreferenceManager.getDefaultSharedPreferences(context).getString("port", "443"));
+ final URL url=new URL("https", hostname, port, path);
+ return url;
+ }
+
+ /**
+ * Poll the server for pending commands. This function must not be called from BroadcastReceivers
+ *
+ * @param context Context instance
+ */
+ public static void pollServer(final Context context){
+ new HttpCallExecutableRunnable("/get", null, context, new PollResultCallback(context), false).execute();
+ }
+
+ /**
+ * Poll the server for pending commands from {@link FonBotMainService}. This function should be used from BroadcastReceviers instead of {@link #pollServer}
+ *
+ * @param context Context instance
+ */
+ public static void safePollServer(final Context context){
+ final Intent intent=new Intent(context, FonBotMainService.class);
+ intent.setAction(FonBotMainService.ACTION_TRIGGER_POLL);
+ context.startService(intent);
+ }