Как получить byteString из файла onActivityResult android?

Я хочу получить такое из файла:

...2 47 ef bf bd cb 92 3a 53 0e 5e ef bf bd ef bf bd d6...

Пытаюсь сделать таким способом:

override fun onActivityResult(requestCode: Int, resultCode: Int, result: Intent?) {
        super.onActivityResult(requestCode, resultCode, result)
        when {
            requestCode == 1 && resultCode == Activity.RESULT_OK -> {
                if (result != null) {
                    val documentFile: DocumentFile = DocumentFile.fromSingleUri(this, result.data!!)!!

                    val hereUrl: Uri? = result.data
                    val inputStream = this.contentResolver.openInputStream(hereUrl!!)
                    val byteArray = inputStream!!.readBytes()


                    Timber.i(byteToHex(byteArray).toString())
                }
            }
      }
}

и вот есть такая функция:

 fun byteToHex(num: ByteArray): ArrayList<String> {
        val stringArray = ArrayList<String>()
        for (i in num.indices){
            val hexDigits = CharArray(2)
            hexDigits[0] = Character.forDigit(i shl 4 and 0xF, 16)
            hexDigits[1] = Character.forDigit(i and 0xF, 16)
            stringArray.add(String(hexDigits))
        }


        return stringArray
    }

и в итоге получаю такое:

00, 01, 02, 03, 04, 05, 06, 07, 08, 09, 0a, 0b, 0c, 0d, 0e, 0f, 00, 01, 02, 03, 04, 05, 06, 07, 08, 09, 0a, 0b, 0c, 0d, 0e, 0f, 00, 01, 02, 03, 04, 05, 06, 07, 08, 09, 0a, 0b, 0c, 0d, 0e, 0f, 00, 01, 02, 03, 04, 05, 06, 07, 08, 09, 0a, 0b, 0c, 0d, 0e, 0f, 00, 01, 02, 03, 04, 05, 06, 07, 08, 09, 0a, 0b, 0c, 0d, 0e, 0f, 00, 01, 02, 03, 04, 05, 06, 07, 08, 09, 0a, 0b, 0c, 0d, 0e, 0f, 00, 01, 02, 03, 04, 05, 06, 07, 08, 09, 0a, 0b, 0c, 0d, 0e, 0f, 00, 01, 02, 03, 04, 05, 06, 07, 08, 09, 0a, 0b, 0c, 0d, 0e, 0f, 00, 01, 02, 03, 04, 05, 06, 07, 08, 09, 0a, 0b, 0c, 0d, 0e, 0f, 00, 01, 02, 03, 04, 05, 06, 07, 08, 09, 0a, 0b, 0c, 0d, 0e, 0f, 00, 01, 02, 03, 04, 05, 06, 07, 08, 09, 0a, 0b, 0c, 0d, 0e, 0f, 00, 01, 02, 03, 04, 05, 06, 07, 08, 09, 0a, 0b, 0c, 0d, 0e, 0f, 00, 01, 02, 03, 04, 05, 06, 07, 08, 09, 0a, 0b, 0c, 0d, 0e, 0f, 00, 01, 02, 03, 04, 05, 06, 07, 08, 09, 0a, 0b, 0c, 0d, 0e, 0f, 00, 

и у меня есть ощущение что я делаю неправильно. Как можно реализовать получение содержания файла другим путем?


Ответы (0 шт):