SAX解析器在Android Pie(9)及更高版本中不起作用

时间:2019-05-31 22:56:00

标签: android xml-parsing rss saxparser

此xml解析代码(专用于RSS提要)在Android 7和8中有效,但在9和Q beta中无效。 setEndTextElementListener从未被击中。

    final RootElement root = new RootElement("rss");
    final Element channelNode = root.getChild("channel");

    channelNode.getChild("title").setEndTextElementListener(new EndTextElementListener()
    {
        public void end(final String body) {
            //this is never hit
        }
    });

    try
    {
        final HttpURLConnection conn = (HttpURLConnection)new URL(url).openConnection();
        conn.setReadTimeout(5000);
        conn.setInstanceFollowRedirects(true);

        if (conn.getResponseCode() == 200)
        {
            final InputStream stream = conn.getInputStream();

            Xml.parse(stream, Xml.Encoding.UTF_8, root.getContentHandler());

            stream.close();
        }
    }
    catch (Exception e)
    {
        e.printStackTrace();
    }

0 个答案:

没有答案