Search code examples
androidgoogle-url-shortener

Google URL shorten decode android


I have a shorten url done by http://goo.gl/ I need to get the original url. Is there any api to do that in ANDROID.

What I tried for make shorter -

compile 'com.andreabaccega:googlshortenerlib:1.0.0'

GoogleShortenerPerformer shortener = new GoogleShortenerPerformer(new OkHttpClient());

String longUrl = "http://www.andreabaccega.com/";

GooglShortenerResult result = shortener.shortenUrl(
    new GooglShortenerRequestBuilder()
        .buildRequest(longUrl)
    );

if ( Status.SUCCESS.equals(result.getStatus()) ) {
    // all ok result.getShortenedUrl() contains the shortened url!
} else if ( Status.IO_EXCEPTION.equals(result.getStatus()) ) {
    // connectivity error. result.getException() returns the thrown exception while performing
    // the request to google servers!
} else {
    // Status.RESPONSE_ERROR
    // this happens if google replies with an unexpected response or if there are some other issues processing
    // the result.

    // result.getException() contains a GooglShortenerException containing a message that can help resolve the issue!
}

Solution

  • I made my solution. What I did -

    I open a webview without visibility then call that url.Then on page load complete I a fetching the url

    WebView webView;
    webView = (WebView)findViewById(R.id.help_webview);
    webview.loadUrl("http://goo.gl/tDn72f");
    webView.setWebViewClient(new WebViewClient() {
    public void onPageFinished(WebView view, String url) {
        String myResult = webView.getUrl();
    }
    });