08 February 2010

bit.ly for android

I want to use the url shortening service bit.ly in an android app I'm working on, and was looking for a .jar or something to help me.

Couldn't find anything made for Android which used the httpclient and json -stuff we have bundled with the the Dalvik vm, so I made one myself today and put it on github.



Easiest way is just go grab the BitlyAndroid.java, put it into your source code and start making short URLs. The github project is just a "proof of concept" android junit project.

Usage:

BitlyAndroid bitly = new BitlyAndroid("bitlyapidemo","R_0da49e0a9118ff35f52f629d2d71bf07");
String shortUrl = bitly.getShortUrl("http://johnsenf.blogspot.com/2009/12/android-sources-and-javadoc-in-eclipse.html");
//shortUrl = "http://bit.ly/9LSEfV"

/Finn

7 comments:

  1. When i try to shorten a link with "#,&" Character i got an exception.

    is there a way to handle it .

    this is a sample of code that works

    String shortUrl = bitly.getShortUrl("http://z"); //Works

    but if i add for example '&' or '%25' to the string it will produce exption :

    - String shortUrl = bitly.getShortUrl("http://z%26"); // Exception

    - String shortUrl = bitly.getShortUrl("http://z&"); // Exception

    Thanks

    ReplyDelete
  2. Tested and it works now , thanks

    ReplyDelete
  3. worked like a charm ...... definitely a pretty useful piece of code ... Thumbs up .....

    ReplyDelete
  4. Is this still supposed to work ?

    I keep getting "WARN/System.err(3547): org.json.JSONException: Value null at results of type org.json.JSONObject$1 cannot be converted to JSONObject
    "

    ReplyDelete
  5. Did you know you can create short links with AdFly and earn $$$ from every visit to your shortened links.

    ReplyDelete
  6. I respect your work and thank you for the excellent information. As a blogger, I am aware of the amount of work you put into it. Online Tool to Ring My Phone You will be able to vibration any of your devices with the aid of this tool. For further details, go here vibration test for phone.

    ReplyDelete