Skip to content

Instantly share code, notes, and snippets.

@Ravinnpawar
Created December 24, 2015 12:39
Show Gist options
  • Save Ravinnpawar/35b117bfaffaec6b3126 to your computer and use it in GitHub Desktop.
Save Ravinnpawar/35b117bfaffaec6b3126 to your computer and use it in GitHub Desktop.
make url short
private void urlShort(final String message) {
new AsyncTask<String, String, GooglShortenerResult>() {
@Override
protected GooglShortenerResult doInBackground(String... params) {
GoogleShortenerPerformer shortener = new GoogleShortenerPerformer(new OkHttpClient());
String longUrl = message;
GooglShortenerResult result = shortener.shortenUrl(
new GooglShortenerRequestBuilder()
.buildRequest(longUrl));
if (result.getStatus().equals("SUCCESS")) {
// all ok result.getShortenedUrl() contains the shortened url!
} else {
// connectivity error. result.getException() returns the thrown exception while performing
// the request to google servers!
}
return result;
}
@Override
protected void onPostExecute(GooglShortenerResult googlShortenerResult) {
super.onPostExecute(googlShortenerResult);
}
}.execute();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment