Clojure on Android

Clojure Android HTTP request

Following the question you linked to above, their (maslurp) works in the android Clojure REPL app, if (.setDoOutput) is set to false instead, per this question, AND you wrap the call in a future (to avoid the android.os.NetworkOnMainThreadException) :

(defn maslurp [url]
(let [a (new java.io.BufferedReader
(new java.io.InputStreamReader
(.getInputStream (doto (.openConnection (new java.net.URL url))
(.setRequestMethod "GET")
(.setDoOutput false) ; false for GET
(.setUseCaches false)))))]
(loop [r (.readLine a) s ""]
(if (nil? r)
s
(recur (.readLine a) (clojure.string/join [s r]))))))

@(future (maslurp "https://www.google.com"))

What is the preferred way to use clojure for making a mobile app (Android and IOs versions)

Using ClojureScript with React Native is now becoming a great answer to this question:

  • Performance of React Native is great.
  • Existing React libraries like Om and Reagent work with React Native.
  • You can benefit from “learn once, write anywhere” knowledge reuse.
  • You benefit from using a stack and language that have significant communities behind them.

And the most compelling reason: React Native allows you to write mobile apps using ClojureScript's strength as a functional language, avoiding the imperative style, mutation, and statefulness.

Can I use Clojure to build a mobile chat application?

Have you looked at Clojurescript? There are definitely possibilities here, though they can get quite involved. One possibility is to use something like react-native or om to actually target the native platforms via javascript.

Probably a bit too advanced to start, but worth being aware of for a broader approach to targeting native platforms with clojure code.



Related Topics



Leave a reply



Submit