Created
March 27, 2019 01:17
-
-
Save davidliu/dbebbe0a58a5035ecd541b573518c6cf to your computer and use it in GitHub Desktop.
Random access through SAF
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MainActivity : AppCompatActivity() { | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_main) | |
val intent = Intent(Intent.ACTION_OPEN_DOCUMENT) | |
intent.type = "*/*" | |
intent.addCategory(Intent.CATEGORY_OPENABLE) | |
startActivityForResult(intent, 1) | |
} | |
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { | |
if (requestCode == 1 && resultCode == RESULT_OK) { | |
if (data != null) { | |
val uri = data.data | |
val pfd = contentResolver.openFileDescriptor(uri, "r") | |
val inputStream = FileInputStream(pfd.fileDescriptor) | |
inputStream.skip(995) | |
inputStream.skip(-3) | |
for (i in 1..10) { | |
val byte = inputStream.read() | |
if (byte == -1) { | |
break; | |
} | |
Log.v("LOL", "${byte.toChar()}"); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment