在onPostExecute()方法中启动浏览器意图

时间:2018-07-11 21:46:04

标签: java android multithreading android-intent

在主要活动中:

download.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ThreadProcess threadProcess = new ThreadProcess();
                threadProcess.execute();

在ThreadProcess类(extends AsyncTask)中,我重写了方法onPostExecute()以启动浏览器意图。我无法做到这一点。请帮忙。

2 个答案:

答案 0 :(得分:0)

@Override
    protected void onPostExecute(String s) {
                    String url = "https://www.stackoverflow.com";
                    Intent browserIntent = new Intent(Intent.ACTION_VIEW);
                    browserIntent.setData(Uri.parse(url));
                    startActivity(browserIntent);
                }

答案 1 :(得分:0)

尝试一下:

download.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent openWebsite = new Intent(Intent.ACTION_VIEW, Uri.parse("www.myWebsite.com")); //Insert website.
                startActivity(openWebsite);
            }
        });