/MainActivity.kt Secret
Created
June 9, 2020 19:31
Star
You must be signed in to star a gist
Demo for crash in CWAC-Document
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
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