Is it possible to send image with default sms in android? - android

I am trying to send image with default android message app. There are three conditions.
I don't want to show intent chooser, which means I don't want to show share bottom sheet.
I want to send message with image.
Have to use Intent.ACTION_SENDTO, not Intent.ACTION_SEND. When I use Intent.ACTION_SEND, it shows intent chooser. I have to send message directly to the default android app.
I tried several code, but it's hard to send message with image. Here are some code that I tried.
1.
val intent = Intent(Intent.ACTION_SENDTO).apply {
putExtra("sms_body", "hello")
putExtra(Intent.EXTRA_STREAM, uri)
data = Uri.parse("smsto:12345")
}
val intent = Intent(Intent.ACTION_SENDTO).apply {
putExtra("sms_body", "hello")
putExtra(Intent.EXTRA_STREAM, uri)
data = Uri.parse("smsto:12345")
type = "image/png"
}

Related

Add image to share intent for a specific app

I'm trying to implement share logic in my application. Intent contains just a basic text, but there are applications that I need to pass additional image. For that reason I am building intent like this:
val intent = Intent().apply {
action = Intent.ACTION_SEND
type = "image/jpeg"
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
putExtra(Intent.EXTRA_TEXT, intentText)
//putExtra(Intent.EXTRA_STREAM, fileToShare)
}
val share = Intent.createChooser(intent, null)
share.putExtra(
Intent.EXTRA_REPLACEMENT_EXTRAS, bundleOf(
"com.google.android.gm" to bundleOf(
Intent.EXTRA_STREAM to fileToShare
),
"com.whatsapp" to bundleOf(
Intent.EXTRA_STREAM to fileToShare
),
)
)
The problem is the apps that need to receive image cant load passed to fileToShare image. There are no errors, just a Toast in Telegram that says that something like Bad file format. In the same time if i just pass exactly same image not in createChooser but in regular intent construction (take a look at the commented line) all works just fine.

Send thumbnail with text - no app can perform this action - error

I would like to display a small preview image of my content to be shared. However, when I run the code, I get a message that no app can perform this action. Unfortunately I don't know what's wrong
private fun shareContentWithPreview() {
val share = Intent.createChooser(Intent().apply {
action = Intent.ACTION_SEND
putExtra(Intent.EXTRA_TEXT, "https://developer.android.com/training/sharing/")
type = "image/jpg"
// (Optional) Here we're setting the title of the content
putExtra(Intent.EXTRA_TITLE, "Introducing content previews")
// (Optional) Here we're passing a content URI to an image to be displayed
val uri: Uri = Uri.parse("android.resource://com.one.myapplication/drawable/rome.jpg")
data = uri
flags = Intent.FLAG_GRANT_READ_URI_PERMISSION
}, null)
startActivity(Intent.createChooser(share, null))
}
Hi m8 think you are passing putExtra(Intent.EXTRA_TEXT, ...), and you should pass putExtra(Intent.EXTRA_STREAM, ...) if you a re passing a Uri

I want to make android application to send picture, message to instagram users using instagram API

I've tried several sources from Google and GitHub but didn't find any authentic source that could help me sending multiple pictures and posts automatically from my android gallery using the scheduler. Is anyone working with the Instagram API? If so, could you please give me some authentic source?
Instead of using the Instagram API, you can directly start an Intent to post an Image or Video to Instagram by opening a "Share with" dialog. This will require user interaction.
String type = "image/*";
String filename = "/myPhoto.jpg";
String mediaPath = Environment.getExternalStorageDirectory() + filename;
private void createInstagramIntent(String type, String mediaPath){
// Create the new Intent using the 'Send' action.
Intent share = new Intent(Intent.ACTION_SEND);
// Set the MIME type
share.setType(type);
// Create the URI from the media
File media = new File(mediaPath);
Uri uri = Uri.fromFile(media);
// Add the URI to the Intent.
share.putExtra(Intent.EXTRA_STREAM, uri);
// Broadcast the Intent.
startActivity(Intent.createChooser(share, "Share to"));
}
Code example taken from https://www.instagram.com/developer/mobile-sharing/android-intents/

Pre fill SMS in facebook messenger

I would like to pre fill a SMS for user who uses facebook messenger.
Here you can find my Kotlin code :
val intent = Intent(Intent.ACTION_SENDTO)
intent.data = Uri.parse("sms:" + smsToString)
intent.putExtra("sms_body", provider.getSmsBody())
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
val list = context!!.packageManager.queryIntentActivities(intent,
PackageManager.MATCH_DEFAULT_ONLY)
val context = activity!!.applicationContext
if (list.isNotEmpty()) {
context.startActivity(intent)
}
This code launch the facebook messenger app with the new sms window, and with the list of contacts prefilled.
But, the sms_body is empty. The same code works when the default sms app is Android Messages.
Is there a solution ?
Thanks :)

How can i send either an image or a video file using ACTION_SEND?

I want to share either an image or a video file using ACTION_SEND. So basically when the users taps on an image and selects "share image/video" it should send either the image selected or the video selected.
here is my code i am using:
if (filep != null) {
}
File sending=new File(filep);
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_SEND);
intent.setDataAndType(Uri.fromFile(sending),getMimeType(sending.getAbsolutePath()));
intent.putExtra(Intent.EXTRA_STREAM, sending);
startActivity(Intent.createChooser(intent , "Share"));
}
private String getMimeType(String url)
{
String parts[]=url.split("\\.");
String extension=parts[parts.length-1];
String type = null;
if (extension != null) {
MimeTypeMap mime = MimeTypeMap.getSingleton();
type = mime.getMimeTypeFromExtension(extension);
}
return type;
So when testing, it takes me to which app i want to use to share with i.e whatsapp, Facebook, email etc. And then when selecting either one, it then says "sharing failed, please try again." I can't seem to figure out why it doesn't work. However i have the same code to display either image or video file full screen with ACTION_VIEW and that seems to work great but not with sharing.
Can anyone assist please?
EXTRA_STREAM needs to be a Uri, and you are not passing a Uri. Use Uri.fromFile() to construct a Uri.
Also, replace setDataAndType() with setType(), as ACTION_SEND does not use the data aspect of the Intent.

Categories

Resources