androidandroid-intentandroid-jetpack-compose

How to open email or any other mail app with intent in android compose


How can I open email app in another screen "tab"?

When I send a reset link from my app, I just want to open the email app for the user. I don't want to call an Intent with the SENDTO action because the user will not be sending any mail

I just want to navigate user from my app to email app (received emails).


Solution

  • This worked for me

    val launcher = rememberLauncherForActivityResult(
        contract = ActivityResultContracts.StartActivityForResult(),
        onResult = { /* Do something when user comes back in app */ }
    )
    
    Button(
        onClick = {
            val intent = Intent(Intent.ACTION_MAIN).apply {
                addCategory(Intent.CATEGORY_APP_EMAIL)
                addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
            }
            launcher.launch(intent)
        },
        content = { Text("Button") },
    )