Any expand URL?

2019-08-29 13:05发布

Anyone know any function which will expand short URL to get coordinates in Android? Like: I have a short URL for which I am getting the expanded URL as follows in browser:

This is link

I want to extract the coordinates from this in Android.

标签: java android url
1条回答
Deceive 欺骗
2楼-- · 2019-08-29 13:19

You Can try this

 public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        new Thread(new Runnable() {
            @Override
            public void run() {
                String expandedURL1=expand("YOUR SHORT URL");
                Log.d("Expanded", "run: "+expandedURL1);
            }
        }).start();

    }

    public static String expand(String url) {
        String s3 = "";
        try {
            HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
            int s = connection.getInputStream().read();
            URL s2 = connection.getURL();
            s3 = String.valueOf(s2);

        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s3;
    }


}

You will get the expanded url in logcat D/Expanded: run:"Expanded URL"

查看更多
登录 后发表回答