Android Intent Sharing From Gridview - android

Creating an a app, where I store bunch of photos in the drawable folder, When the user longpress on a photo brings up a menu, one of the options is to share.I can get the contextmenu up, but have no clue how to share from the grid menu.
I also have the expand it is bring up single image in own view and can share from there.
But when the user selects the Image from the gridview I have no Idea how to share that one.
this is the method i call when user selects share option
public Intent intentShare() {
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("image/jpeg");
share.putExtra(Intent.EXTRA_STREAM, Uri.parse("android.resource://your.package.here/drawable/"+share.putExtra("id", lastPosition)));
startActivity(Intent.createChooser(share, "Share Image"));
return share;
}
I have seen this possible option/solution on a couple of other questions
Bitmap icon = mBitmap;
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("image/jpeg");
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
icon.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
File f = new File(Environment.getExternalStorageDirectory() + File.separator + "temporary_file.jpg");
try {
f.createNewFile();
FileOutputStream fo = new FileOutputStream(f);
fo.write(bytes.toByteArray());
} catch (IOException e) {
e.printStackTrace();
}
share.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///sdcard/temporary_file.jpg"));
startActivity(Intent.createChooser(share, "Share Image"));
But I have no idea how to initialize mBitmap if that works ?
The entire code can be found here: http://pastie.org/private/gdpyn2t55h0gp1vp1kika

You can convert the Bitmap from resource using code like this:
Bitmap mBitmap = BitmapFactory.decodeResource(getResources(), mThumbIds[lastPosition]);
now you can share it as you share in Expanded view.

Related

How to implement an Image Slider that becomes full screen when clicked?

How can I add an image slider that becomes full screen when clicked?
I would like to be able to preview the images in full screen mode and be able to share it or zoom it. What are some ways that I can implement this?
Use this lib to zoom image and for sharing an image you can use share intent
Bitmap icon = mBitmap;
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("image/jpeg");
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
icon.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
File f = new File(Environment.getExternalStorageDirectory() + File.separator + "temporary_file.jpg");
try {
f.createNewFile();
FileOutputStream fo = new FileOutputStream(f);
fo.write(bytes.toByteArray());
} catch (IOException e) {
e.printStackTrace();
}
share.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///sdcard/temporary_file.jpg"));
startActivity(Intent.createChooser(share, "Share Image"));

How can I share an image that I have taken in my app?

I currently have an app in which I'm taking photos and I'm trying to share them directly through the app. The problem I'm having is that when the chooser comes up and I pick one, I get an error toast that pops up and says "Unable to attach file". Then it just takes me back into the app and everything else still works. I'm assuming that this means that I have to save the image first, but I'm not sure if I'm doing that correctly. I found some examples online of how to save the images but I'm not sure if that's the problem or if the share intent is the problem.
final Button shareButton = (Button) findViewById(R.id.shareButton);
shareButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
imageView.setDrawingCacheEnabled(true);
Bitmap b = imageView.getDrawingCache();
MediaStore.Images.Media.insertImage(getContentResolver(), b, "title", "description");
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("image/jpeg");
BitmapDrawable bitmapDrawable = (BitmapDrawable) imageView.getDrawable();
Bitmap image = bitmapDrawable.getBitmap();
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
image.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
File f = new File(Environment.getExternalStorageDirectory() + File.separator + "temp.jpg");
try {
f.createNewFile();
FileOutputStream fo = new FileOutputStream(f);
fo.write(bytes.toByteArray());
} catch (IOException e) {
e.printStackTrace();
}
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(Environment.getExternalStorageDirectory().getPath()));
startActivity(Intent.createChooser(shareIntent, "Share Image"));
}
});
I have "title" and "description" in as placeholders until I can get this to work.
Try to replace :
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(Environment.getExternalStorageDirectory().getPath(‌​)));
With :
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(f));
This question can help you.

How to share image and text with custom formatting?

I am able to share image and multiple text using the following code:
Bitmap icon = BitmapFactory.decodeResource(getResources(),
R.mipmap.ic_launcher);
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("*/*");
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
icon.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
File f = new File(Environment.getExternalStorageDirectory()
+ File.separator + "temporary_file.jpg");
try {
f.createNewFile();
FileOutputStream fo = new FileOutputStream(f);
fo.write(bytes.toByteArray());
} catch (IOException e) {
e.printStackTrace();
}
share.putExtra(android.content.Intent.EXTRA_SUBJECT, "this is subject");
share.putExtra(Intent.EXTRA_TEXT, "HeadLine.\nIntroText");
share.putExtra(Intent.EXTRA_STREAM,
Uri.parse("file:///sdcard/temporary_file.jpg"));
startActivity(Intent.createChooser(share, "Share Image"));
I tested it in whatsapp share and it is working. Here is the current share output:
-->> Image display
-->> Subject display
-->> Extra text display
But I am using custom formatting and it is not working. Here is the custom formatting:
-->> Image display in left side with 20*20 -->> Subject display in right side
-->> Extra text display in right side
Can this be done?

Share content to Messenger or Line or other like Facebook or Tweeter

Hi I am new to develop application in android.
I saw other apps, they use share to friends with Messenger, or Facebook..
for instant, I share it to Messenger, then in the content should show some texts and the link of app!!
How can I do that? anyone please help!!!
I have tried the answer in this site to share, but it works only with SMS and Gmail, but if I share to Messenger, it shows nothing!
Try this code for sharing drawable image with link and text.
Follow this steps
Step 1 :- Take one button in your layout.xml for sharing your content.
Step 2 :- set onClickListner for this button in your Activity.java.
Step 3 :- Put this code to your Activity.java file Button setOnClickListner.
String myText = "share text though this string";
Bitmap icon = BitmapFactory.decodeResource(getResources(),
R.mipmap.icon_256);
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("image/jpg");
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
icon.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
File f = new File(Environment.getExternalStorageDirectory()
+ File.separator + "temporary_file.jpg");
try {
f.createNewFile();
FileOutputStream fo = new FileOutputStream(f);
fo.write(bytes.toByteArray());
} catch (IOException e) {
e.printStackTrace();
}
String extraText = myText + "\n\nhttps://www.google.co.in";
share.putExtra(Intent.EXTRA_TEXT,extraText);
share.putExtra(Intent.EXTRA_STREAM,
Uri.fromFile(f));
startActivity(Intent.createChooser(share, "Share Image"));

How to share image and text to facebook app

I am trying to share an image and text.
When I'm doing this:
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("image/*");
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
screenshot.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
File f = new File(Environment.getExternalStorageDirectory()
+ File.separator + "temporary_file.jpg");
try {
f.createNewFile();
FileOutputStream fo = new FileOutputStream(f);
fo.write(bytes.toByteArray());
} catch (IOException e) {
e.printStackTrace();
}
share.putExtra(Intent.EXTRA_STREAM,
Uri.parse("file:///sdcard/temporary_file.jpg"));
share.putExtra(android.content.Intent.EXTRA_TEXT, textToShare);
startActivityForResult(Intent.createChooser(share, "Share Image"),
FROM_SHARE);
It works greate on all apps (that was choosen from the popup dialog like Gmail) except for facebook, facebook takes only the image and not the text.
Is there a whay to pass an extra text with an image to the facebook app?
Thanks!
There is a bug in FACEBOOK I have the same problem If you really want to do that anyhow you need to use facebook SDK for that and use Facebook ShareDialog.

Categories

Resources