Home > Mobile >  When program is run the email app do not opens on mobile phone. OR when tried to modify code the app
When program is run the email app do not opens on mobile phone. OR when tried to modify code the app

Time:04-03

Java Code for intent

the email app is not opening on my android device. there are no error in code but don't know why app isn't working

CodePudding user response:

You are using an old or deprecated way to start activity for ACTION_SEND scenarios. Use below snippet for the correct way.

val sendIntent: Intent = Intent().apply {
    action = Intent.ACTION_SEND
    putExtra(Intent.EXTRA_TEXT, "This is my text to send.")
    type = "text/plain"
}

val shareIntent = Intent.createChooser(sendIntent, null)
startActivity(shareIntent)

You can check out the code snippet and detailed explanation here. https://developer.android.com/training/sharing/send#using-android-system-sharesheet

CodePudding user response:

Starting with API level 30, if you're targeting that version or higher, your app cannot see, or directly interact with, most external packages without explicitly requesting allowance.

Check this answer, it works for me.

https://stackoverflow.com/a/65166064/7248394

  • Related