关于android:使用GDK打开URL而不显示浏览器窗口 | 珊瑚贝

Open URL without showing the browser window using GDK


我有一个应用程序(使用 GDK 开发),玻璃会在其中打开一个 URL,并从主屏幕触发语音。该 URL 实际上只是一个空白页面,其目的是触发另一台 PC 上的某些进程。我能找到打开 URL 的唯一方法是使用内置浏览器启动活动,例如:

1
2
3
4
String url =”http://www.abc123.com”;
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
startActivity(intent);

加载后,我必须在触摸板处向下滑动才能关闭浏览器窗口。有没有办法在后台打开 URL 并在加载(本身)后关闭活动而不显示浏览器窗口?
我真的不需要浏览器窗口,因为页面上没有显示任何内容。


你能发出一个http请求吗?

这里是文档或者试试 Square 的 OkHttp。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
@Override
protected void onCreate(Bundle bundle) {
    super.onCreate(bundle);

    new Thread(new Runnable() {
        @Override
        public void run() {
            URL url = null;
            HttpURLConnection urlConnection = null;
            try {
                url = new URL(“http://www.abc123.com/”);
                urlConnection = (HttpURLConnection) url.openConnection();
            } catch (MalformedURLException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                urlConnection.disconnect();
            }
        }
    }).start();
}

注意:我没有测试。您还可以使用 AsyncTask 或其他机制代替 Thread.


来源:https://www.codenong.com/25905658/

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_9036.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?