Skip to content

Instantly share code, notes, and snippets.

@gmk57
Created June 9, 2020 19:31
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save gmk57/319d94234f2a7ec6c3dfb97b3d28c98f to your computer and use it in GitHub Desktop.
Demo for crash in CWAC-Document
package gmk57.test41c6
import android.app.Activity
import android.content.Intent
import android.os.Bundle
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import com.commonsware.cwac.document.DocumentFileCompat
import kotlinx.android.synthetic.main.activity_main.*
private const val TAG = "MainActivity"
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
get.setOnClickListener {
val intent = Intent(Intent.ACTION_GET_CONTENT)
.setType("*/*")
.addCategory(Intent.CATEGORY_OPENABLE)
startActivityForResult(intent, 0)
}
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
if (requestCode == 0) {
if (resultCode == Activity.RESULT_OK) {
data?.data?.let {
val file = DocumentFileCompat.fromSingleUri(this, it)
file?.let { Log.d(TAG, "file name: ${file.name}") }
}
}
} else super.onActivityResult(requestCode, resultCode, data)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment