我正在尝试使用textFile方法通知用户我的应用程序有一个新的更新。我在Playstore和google drive上都有这个应用程序。我已经成功地通过编程获得了我的应用程序的版本代码,现在的问题是读取我托管在google drive上的一个文本文件中的版本代码。
我找到了下面的代码,但当我从google drive使用我的url时,它什么也没有返回。我是不是遗漏了什么?
private static String getUrlContents(String theUrl)
{
    StringBuilder content = new StringBuilder();
    // many of these calls can throw exceptions, so i've just
    // wrapped them all in one try/catch statement.
    try
    {
        // create a url object
        URL url = new URL(theUrl);
        // create a urlconnection object
        URLConnection urlConnection = url.openConnection();
        // wrap the urlconnection in a bufferedreader
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
        String line;
        // read from the urlconnection via the bufferedreader
        while ((line = bufferedReader.readLine()) != null)
        {
            content.append(line + "\n");
        }
        bufferedReader.close();
    }
    catch(Exception e)
    {
        e.printStackTrace();
    }
    return content.toString();
}发布于 2017-04-18 18:26:39
我想我在另一个帖子中找到了解决方案(如评论中所建议的):
您必须添加以下内容:
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);添加到onCreate函数。
这是给manifestFile的:
<uses-permission android:name="android.permission.INTERNET"/>https://stackoverflow.com/questions/40408460
复制相似问题