Created
December 24, 2015 12:39
-
-
Save Ravinnpawar/35b117bfaffaec6b3126 to your computer and use it in GitHub Desktop.
make url short
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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