我无法在Android Pie中创建文件

时间:2019-07-15 00:28:22

标签: java android kotlin

我想创建要上传到Android Pie中的服务器的文件, 当我使用低于API 28的android时,我使用的是这样

    File file = new File(uri);

在android pie中,uri会像这样 content://downloads/public_downloads/114/

在低于派的android系统中,我得到了这样的uri external_storage/com.blah/blah/blah.pdf

我在这里尝试

class PickImage : FlutterActivity() {
 val intent = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            Intent(Intent.ACTION_OPEN_DOCUMENT).apply {
                addCategory(Intent.CATEGORY_OPENABLE)
                type = "application/pdf"
            }
        } else {
            TODO("VERSION.SDK_INT < KITKAT")
        }
        startActivityForResult(intent, requestCode)
    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        if (requestCode == this.requestCode && resultCode == Activity.RESULT_OK) {
            try {
                val uri = data?.data
                val file = File(uri)
         //this error when im using android pie
            } catch (e: Exception) {
                e.printStackTrace()
            }
        }
        super.onActivityResult(requestCode, resultCode, data)
    }

}

请帮助。谢谢

0 个答案:

没有答案