有没有办法限制Android上的下载任务

时间:2019-05-12 22:18:06

标签: java android json kotlin

我要用Kotlin / Android编写一个小应用程序,ich希望从Api中执行下载任务,但是该站点很长,而且下载要花很多时间,我如何限制下载大小?例如,仅从API的第一个Json Objekts起

 fun downloadData (address : String) :String{
    var result = ""
    var url : URL
    var urlConnection : HttpURLConnection?

        url = URL(address)
        urlConnection = url.openConnection() as HttpURLConnection
        val input = urlConnection.getInputStream()
        val reader = InputStreamReader(input)
        var data = reader.read()

        while (data != -1) {
            val current = data.toChar()
            result += current
            data = reader.read()
        }
        return result
}

0 个答案:

没有答案