任何扩展网址?

时间:2018-06-15 11:42:52

标签: java android url

任何人都知道任何会扩展短网址以获取Android坐标的功能吗?比如:我有一个简短的URL,我在浏览器中获得扩展的URL:

This is link

我想在Android中从中提取坐标。

1 个答案:

答案 0 :(得分:1)

你可以尝试这个

 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;
    }


}

您将在logcat中获得扩展的URL D /扩展:运行:“扩展的URL”