I want to have a share intent where it sends the message "here" and when the user clicks on the message, it takes them to my app in the google play store. Currently I'm not getting any text at all in the message
val shareMessage = SpannableString("Here")
shareMessage.setSpan(URLSpan("https://play.google.com/store/apps/details?id=" + BuildConfig.APPLICATION_ID), 0, 4, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
val sendIntent: Intent = Intent().apply {
action = Intent.ACTION_SEND
putExtra(Intent.EXTRA_TEXT, shareMessage)
type = "text/plain"
}
val shareIntent = Intent.createChooser(sendIntent, null)
if (shareIntent.resolveActivity(context.packageManager) != null) {
context.startActivity(shareIntent)
}
Related
This is my hyperlink
String linkText = "Visit the <a href='http://stackoverflow.com'>StackOverflow</a> web page."
I have add this in below function
fun whatsappshr(context: Context, displayData: Display_data) {
val message : String = displayData.appdata + linkText
val Intentfun = Intent(Intent.ACTION_SEND)
Intentfun.type = "text/plain"
Intentfun.setPackage("com.whatsapp")
Intentfun.putExtra(Intent.EXTRA_TEXT, message)
try {
ContextCompat.startActivity(itemView.context, Intentfun, null)
} catch (ex: ActivityNotFoundException) {
Toast.makeText(itemView.context, "Whatsapp not Installed", Toast.LENGTH_SHORT).show()
}
}
when my app share the data via Intent, it does not send a link. It send the whole data from linkText.
Is there any way to send hyperlink via android intent? Guys, please help me to resolve this.
I am having an issue with Email Intent in Android.
The recipients field is not populating properly.
My code is as such:
Extensions.kt
// Returns a Mail Intent
fun requireMailIntent(subject: String, body: String) = Intent(Intent.ACTION_SENDTO).apply {
data = Uri.parse("mailto:")
putExtra(Intent.EXTRA_EMAIL, arrayOf("email#gmail.com"))
putExtra(Intent.EXTRA_SUBJECT, subject)
putExtra(Intent.EXTRA_TEXT,body)
}
/**
* Checks whether the intent has an app that can
* handle it.
* Should be called before starting an intent
**/
fun Intent.hasSuccessor(context: Context) = resolveActivity(context.packageManager) != null
Fragment.kt
// Submit button
binding.ButtonSubmit.setOnClickListener {
val emailConstruct = constructEmail()
val intent = requireMailIntent(emailConstruct.first, emailConstruct.second)
if(intent.hasSuccessor(requireContext())){
Log.v("INTENT_TEST", "Launching Intent")
startActivity(intent)
}else{
Log.v("INTENT_TEST", "No app found")
}
}
private fun constructEmail(): Pair<String,String>{
val subject = "MES :: Bug Report :: ${viewModel.bugIdentified}"
val message = "Below are the steps \n ${viewModel.bugSteps}"
return Pair(subject, message)
}
Manifest.xml
<!-- For basic package querying, ie browsers, email... -->
<uses-permission
android:name="android.permission.QUERY_ALL_PACKAGES"
tools:ignore="QueryAllPackagesPermission" />
Gradle
// SDK Versions
sdk_compiled_version = 30
sdk_minimum_version = 24
// Build tools
build_tools = "29.0.3"
Upon clicking the button, Android shows me the app chooser, but when i click Gmail, everything populates except the recipients field.
Can someone please help ?
Try using URI
val uriText = "mailto:contact#example.com" +
"?subject=" + "your subject here" +
"&body=" + body
val uri = Uri.parse(uriText)
val sendIntent = Intent(Intent.ACTION_SENDTO)
sendIntent.data = uri
startActivity(Intent.createChooser(sendIntent, "Send Email").addFlags(FLAG_ACTIVITY_NEW_TASK))
Is there a way to launch the Sharesheet (see https://developer.android.com/training/sharing/send) without having to wrap the called intent into the createChooser-returned intent, but rather specifying the wish for the Sharesheet as an ACTION and/or EXTRA. E.g. instead of
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)
Something like:
val shareIntent: Intent = Intent().apply {
action = Intent.ACTION_CREATE_CHOOSER
putExtra(Intent.EXTRA_ACTION_TYPE, Intent.ACTION_SEND)
putExtra(Intent.EXTRA_TEXT, "This is my text to send.")
type = "text/plain"
}
startActivity(shareIntent)
My main goal is to get a Sharesheet that shows my frequent contacts/apps at the top. I'm not interested in all the functionality that createChooser might provide.
Should work at least in Android 11.
I try to share url, pointing to some video in internet, and some text. Url and text need to be shared together, on one click to "share" button. I already know how to share video + text, when video is downloaded to Android device. But I want to share just url to video + text. So, url is actually text by itself, and I can't find way to share 2 separate texts. When I try following:
putExtra( Intent.EXTRA_TEXT, "url")
putExtra( Intent.EXTRA_TEXT, "text2")
only text2 is shared.
Here is my code:
val sendIntent: Intent = Intent().apply {
action = Intent.ACTION_SEND
type = "*/*"
putExtra(Intent.EXTRA_TEXT, "url")
putExtra(Intent.EXTRA_TEXT, "text2")
}
val shareIntent = Intent.createChooser(sendIntent, null)
startActivity(shareIntent)
Why is this happening?
You are overwriting the text with "text2", this is the reason why only that part is shared, see the corresponding method inside the Intent class:
public #NonNull Intent putExtra(String name, String value) {
if (mExtras == null) {
mExtras = new Bundle();
}
mExtras.putString(name, value);
return this;
}
How to fix this?
Just combine the URL and the text, e.g.:
putExtra(Intent.EXTRA_TEXT, "url" + "\n\n" + "your text");
I am using the following code snippets from Android official documentation to share content through applications using Intent but it says "No apps can perform this action." on a physical device. I have messengers, email client and text message clients installed.
val intent = Intent().apply {
intent.action = Intent.ACTION_SEND
intent.type = "text/plain"
intent.putExtra(Intent.EXTRA_TEXT, "Text to share")
}
startActivity(Intent.createChooser(intent, "Sharing"))
I think you should change your intent initialization with apply to this:
val intent = Intent().apply {
action = Intent.ACTION_SEND
type = "text/plain"
putExtra(Intent.EXTRA_TEXT, "Text to share")
}
When you modify the intent variable inside the apply you are modifying the activity intent not the brand new intent.
copy this code and you will see what i'm talking about:
val intent_1 = Intent().apply {
intent.action = Intent.ACTION_SEND
intent.type = "text/plain"
intent.putExtra(Intent.EXTRA_TEXT, "Text to share")
}
This is what I know:
As Fredy Mederos said, the value that you are modified is the Activity.getIntent, not the new Intent.
You should write like this:
val intent = Intent().apply {
action = Intent.ACTION_SEND
type = "text/plain"
putExtra(Intent.EXTRA_TEXT, "Text to share")
}
or more precise:
val intent = Intent().apply {
this.action = Intent.ACTION_SEND
this.type = "text/plain"
this.putExtra(Intent.EXTRA_TEXT, "Text to share")
}
the this is pointed to your initialized new Intent().
The following code works instead of above posted in the question.
val i = Intent(Intent.ACTION_SEND)
i.type = "text/plain"
i.putExtra(Intent.EXTRA_TEXT, "Content to share")
startActivity(Intent.createChooser(i, "Sharing"))
I am not sure why the code in the question does not work but my guess is that intent is related to the activity's intent and it works when I instantiated another object from Intent class.
you can replace startActivity(Intent.createChooser(i, "Sharing"))
by startActivity(i)