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
with(binding) { | |
rgChoices.setOnCheckedChangeListener { _, index -> | |
Toast.makeText( | |
this@MainActivity, | |
"Checked index $index", | |
Toast.LENGTH_SHORT | |
).show() | |
when (index) { | |
R.id.rb_choice1 -> { |
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
<RadioGroup | |
android:id="@+id/rg_choices" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:layout_margin="24dp" | |
app:layout_constraintEnd_toEndOf="parent" | |
app:layout_constraintStart_toStartOf="parent" | |
app:layout_constraintTop_toBottomOf="@id/textView"> | |
<RadioButton | |
android:id="@+id/rb_choice1" |
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
// rgChoices - RadioGroup's id | |
binding.rgChoices.clearCheck() | |
binding.rgChoices.check(-1) // -1 to clear the selection |
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
val clipboardManager = context.getSystemService(CLIPBOARD_SERVICE) as ClipboardManager | |
// When setting the clip board text. | |
val clipData = ClipData.newPlainText(/* label = */ "Sample copy data",/* text = */ context.getString(R.string.clip_preview)) | |
.apply { | |
description.extras = PersistableBundle().apply { | |
// only available for Android13 or higher | |
putBoolean(ClipDescription.EXTRA_IS_SENSITIVE, true) | |
// use raw string for older versions | |
// android.content.extra.IS_SENSITIVE | |
} |
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
<queries> | |
<intent> | |
<action android:name="android.media.action.IMAGE_CAPTURE" /> | |
</intent> | |
</queries> |
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
private fun launchCameraIntent() { | |
val takePhotoIntent = Intent(MediaStore.ACTION_IMAGE_CAPTURE) | |
// Ensure that there's a camera activity to handle the intent | |
// Android11 or higher needs the <query> tag to be added in the Android Manifest file. | |
// It depend on the device, if by-default camera package is visible or not | |
takePhotoIntent.resolveActivity(packageManager)?.also { | |
// Create the File where the photo should go | |
val photoFile: File? = try { | |
createImageFile() | |
} catch (ex: IOException) { |
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
adb shell dumpsys package queries |
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
// create ActivityResultContract | |
val getContent = | |
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result -> | |
result?.let { nonNullableResult -> | |
when (nonNullableResult.resultCode == RESULT_OK) { | |
true -> { | |
val intent = nonNullableResult.data | |
intent?.data?.let { uri -> | |
// process data | |
} |
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
@Composable | |
fun PhotoPickerResultComposable() { | |
var result by rememberSaveable { mutableStateOf<Uri?>(null) } | |
val launcher = | |
rememberLauncherForActivityResult(ActivityResultContracts.StartActivityForResult()) { | |
result = it.data?.data | |
} | |
Column( | |
verticalArrangement = Arrangement.Center, | |
horizontalAlignment = Alignment.CenterHorizontally |
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
Intent(MediaStore.ACTION_PICK_IMAGES).apply { | |
type = "image/*" | |
// only videos | |
type = "video/*" | |
} |