0

I have a custom keyboard, where I need to send an image instead of text (preferably only if the user is in the message app)... But I'm a bit unsure of how to specifically send the image to the current app/activity...

So what I have right now is that when the user clicks on one of my images in my custom keyboard, I run the following:

Drawable mDrawable = ResourcesCompat.getDrawable(getResources(), R.drawable.rsz_emoji, null);
Bitmap mBitmap = ((BitmapDrawable)mDrawable).getBitmap();
String path = MediaStore.Images.Media.insertImage(getContentResolver(), mBitmap, "Emoticon", null);

Intent picMessageIntent = new Intent(Intent.ACTION_SEND);
picMessageIntent.putExtra(Intent.EXTRA_STREAM, path);
picMessageIntent.setType("image/jpeg");
Intent new_intent = Intent.createChooser(picMessageIntent, "Share via");
new_intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(new_intent);

So this opens up the share popup, but ideally, what I want is to add the image to the message... So does anyone know what approach can give me the desired effect?

user969043
  • 756
  • 2
  • 13
  • 34

1 Answers1

2

Finally got it working!

Drawable mDrawable = ResourcesCompat.getDrawable(getResources(), R.drawable.rsz_emoji, null);
Bitmap mBitmap = ((BitmapDrawable)mDrawable).getBitmap();
String path = MediaStore.Images.Media.insertImage(getContentResolver(), mBitmap, "Emoticon", null);
Uri fileUri = Uri.parse(path);

Intent picMessageIntent = new Intent(Intent.ACTION_SEND);
picMessageIntent.setPackage("com.android.mms");
picMessageIntent.putExtra(Intent.EXTRA_STREAM, fileUri);
picMessageIntent.setType("image/png");
picMessageIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(picMessageIntent);
user969043
  • 756
  • 2
  • 13
  • 34
  • Hi, do you can share your project? I'm developing a project with same purpose of yours project. I appreciate it. – Regis May 02 '17 at 17:15
  • @RegisZanandrea It was a project for a client, so the project is a live app on Google Play, so I can't really share it... Is there a specific code part you'd want to see other than the above? It's been almost a year and a half, since I worked on it, so it might be a bit outdated though... – user969043 May 03 '17 at 11:06
  • I have to put a GridView in the keyboard, but I don't know how. – Regis May 03 '17 at 12:27
  • @RegisZanandrea http://stackoverflow.com/questions/33610139/android-custom-keyboard-layout-leaving-a-margin-of-white-at-the-side/41777788#41777788 My layout worked like this... – user969043 May 03 '17 at 12:39
  • Thanks. I appreciate it. :) – Regis May 03 '17 at 12:45