我正在使用PRDownloader。我想从我的Google云端硬盘下载文件,因此我需要提供Authorization: Bearer <ACCESS_TOKEN>
..如何使用PRDownloader进行此操作?我从网站上看不到任何方法可以做到这一点,但也许有一些非正式的方式?
答案 0 :(得分:0)
我偶然发现了同样的问题,最终改用Fetch。一个工作示例如下所示。重要的行可以在下载方法中找到:
request.addHeader("Authorization", "Bearer $accessToken")
这是完整的DummyActivity:
class MainActivity : AppCompatActivity() {
private lateinit var fetch: Fetch
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
Timber.plant(Timber.DebugTree())
val okHttpClient = OkHttpClient.Builder().build()
val fetchConfiguration =
FetchConfiguration.Builder(this)
.setDownloadConcurrentLimit(10)
.setProgressReportingInterval(100)
.setHttpDownloader(OkHttpDownloader(okHttpClient))
.build()
fetch = getInstance(fetchConfiguration)
button.setOnClickListener { download() }
}
private fun download() {
val url = "https://yourdomain.com/download/path.zip"
val dirPath = getExternalFilesDir(null)?.path
val fileName = "ResultFileName.zip"
val accessToken = "your_access_token"
val request = Request(url, Uri.fromFile(File(dirPath, fileName)))
request.priority = Priority.HIGH
request.networkType = NetworkType.ALL
request.addHeader("Authorization", "Bearer $accessToken")
fetch.enqueue(
request,
Func { updatedRequest -> Timber.d("request updated: ${updatedRequest.id})") },
Func { error: Error? -> Timber.d("Error: ${error?.name}")}
)
}
}