有没有展开网址? [英] Any expand URL?

查看:22
本文介绍了有没有展开网址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道在Android中可以扩展短网址以获取坐标的任何功能吗?喜欢:我有一个短网址,我在浏览器中得到如下扩展网址:

这是链接我想在 Android 中从中提取坐标.

解决方案

你可以试试这个

 公共类 MainActivity 扩展 AppCompatActivity {@覆盖protected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);新线程(新运行(){@覆盖公共无效运行(){String extendedURL1=expand("你的短网址");Log.d("Expanded", "运行:"+expandedURL1);}}).开始();}公共静态字符串扩展(字符串网址){字符串 s3 = "";尝试 {HttpURLConnection 连接 = (HttpURLConnection) 新 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();}返回 s3;}}

你会在logcat中得到扩展后的urlD/Expanded: 运行:"Expanded URL"

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.

解决方案

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"

这篇关于有没有展开网址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆