Share button in android app [duplicate] - android

This question already has answers here:
How to share a file in Android programmatically
(5 answers)
Closed 5 years ago.
In my app, i am trying to implement Share button, Which when clicked should give me list of all the social media icons. I was looking at some examples, i like the way media is shared on "WhatApp", u selected the media, click on share, the a window slides up from bottom with the list of social media icons, i saw this kind of implemenatation in othe apps also, and you slide left or right to see more icons. How do i implement something like this in my app. Any examples would be appreciated. below is the screen shot of one of the apps.

share.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("image/*");// You Can set source type here like video, image text, etc.
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(fileUrl);
shareIntent.setFlags(FLAG_ACTIVITY_NEW_TASK);
startActivity(Intent.createChooser(shareIntent, "Share File Using!"));
}
});
here share is my ImageView
let me know if any query

Firstly set that image on ImageView and then use this code to share the image :-
share.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Uri bmpUri = getLocalBitmapUri(img);
if (bmpUri != null) {
// Construct a ShareIntent with link to image
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, bmpUri);
shareIntent.setType("image/*");
// Launch sharing dialog for image
startActivity(Intent.createChooser(shareIntent, "Share Image"));
} else {
// ...sharing failed, handle error
}
}
});
"img" is my image which i want to share.

Related

How to share image from link ,i.e, without downloading the image just share using a button

I am beginner in android studio and i think it will be easy but also I am not getting that
How to share image from link ,i.e, without downloading the image just share on social media like whats app .I can download the image and then share and then delete that but I do not want to do that. I am using glide library to load the image in Image view and then when a user click on a button it will just share its image which is showing in image view and whose link i have and then come back to the app.
I am using Glide library for loading image.
Any help will be grateful.
Thanks in advance.
first you need to load image in glide(as you are using glide ) then you can share it to anywhere but image will be saved to storage
code to load image from glide (image is being saved to storage, you can delete it later)
Glide.with(getApplicationContext())
.load(imagelink) \\link of your image file (url)
.asBitmap().skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.NONE)
.into(new SimpleTarget<Bitmap>(250, 250) {
#Override
public void onResourceReady(Bitmap resource, GlideAnimation glideAnimation) {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_TEXT, "Hey view/download this image");
String path = MediaStore.Images.Media.insertImage(getContentResolver(), resource, "", null);
Uri screenshotUri = Uri.parse(path);
intent.putExtra(Intent.EXTRA_STREAM, screenshotUri);
intent.setType("image/*");
startActivity(Intent.createChooser(intent, "Share image via..."));
}
#Override
public void onLoadFailed(Exception e, Drawable errorDrawable) {
Toast.makeText(getApplicationContext(), "Something went wrong", Toast.LENGTH_SHORT).show();
super.onLoadFailed(e, errorDrawable);
}
#Override
public void onLoadStarted(Drawable placeholder) {
Toast.makeText(getApplicationContext(), "Starting", Toast.LENGTH_SHORT).show();
super.onLoadStarted(placeholder);
}
});
If you want then delete that image from storage by adding some more code
Actually link is also a text, so you can share it like this:
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, yourUrlOfImage);
sendIntent.setType("text/plain");
startActivity(sendIntent);

How to open a specific album or photo in facebook app using intent from your own Android App

How to open an album or photo in facebook app using intent from your own Android App?
I been searching for the specific answer for this one. Most question are about how to open a facebook page via intent.
I saw this one (regards to Sunny a Sr. Software engineer at iAppStreet) but it doesn't work.
public Intent getOpenFacebookIntent(String pId) {
try {
activity.getPackageManager().getPackageInfo("com.facebook.katana", 0);
return new Intent(Intent.ACTION_VIEW, Uri.parse("facebook:/photos?album=0&photo=" + pId+"&user="+ownerId));
} catch (Exception e) {
return new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.facebook.com/"));
}
}
startActivity(getOpenFacebookIntent(pid));
thanks.
Actually i made this question to help those who have the same problem like me. As of today (28 March 2016) i just found out how to open an album using intent but i cannot open a photo using intent in the facebook app. I am a beginner in android programming so please bear with me.
I used a button to implement this. Here is the code:
Button buttonOpenALbum = (Button) findViewById(R.id.button);
buttonOpenALbum.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
//It is a album from a facebook page # www.facebook.com/thinkingarmy
String albumID = "575146485903630";
String userID = "575145312570414";
String url = "facebook:/photos?album="+albumID+"&user="+userID;
Uri uri = Uri.parse(url);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
}
});
If you want to get the albumID and userID of a facebook album try searching on google how or try this one if it helps, https://www.youtube.com/watch?v=sMEmlpmCHLc
Modifying the code to open a specific photo has not produce the expected result. Even though I included the photoID, you still end up in the album. Here is the code:
Button buttonOpenPhoto = (Button) findViewById(R.id.button);
buttonOpenPhoto.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
//It is a album from a facebook page # www.facebook.com/thinkingarmy
String albumID = "575146485903630";
String userID = "575145312570414";
String photoID = "803154029769540";
String url = "facebook:/photos?album="+albumID+"&photo="+photoID+"&user="+userID;
Uri uri = Uri.parse(url);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
}
});
I can't be sure why. I tried looking but some say the urls of facebook is undocumented. If I may, I think you cannot open a specific photo because upon observation, facebook open a photo in full screen, meaning it is a different Activity than the Main Activity which handles the incoming Intent. The Main Activity of the facebook app only handles the intent up to opening a specific album.
I hope I can help other "new android coders" with my first post.
NB: I just learn coding using google and stackoverflow. It's my way of giving back. Thanks.
Launch a view intent with the following URL
https://www.facebook.com/photo.php?fbid={photo_id}
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
ctx.startActivity(browserIntent);
If the app is installed, it will prompt the user to open in app, otherwise it will use the browser
Some useful information at Open Facebook Page in Facebook App (if installed) on Android
In particular, new versions of facebook app work with
Uri.parse("fb://facewebmodal/f?href=" + FACEBOOKURL
I found this the simplest approach to acheive what was needed.
Note also that to get the URL you can go to the facebook album (on facebook desktop), click the three dots next to "Edit" and "Tag" and select "Get Link". I found this more reliable than simply copying the URL from the browser.

CanĀ“t do a tweet with twitter app - android

i have a problem with my app, i tried this code to do a tweet from my app without using the sdk:
ImageView Twitter = (ImageView) findViewById(R.id.imageView4);
Twitter.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("plain/text");
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT,
"This is the text that will be shared.");
startActivity(Intent.createChooser(sharingIntent,
"Share via"));
}
});
I just wanted to share text+link, but when i press the button, TWITTER DOESNT EXISTS, facebook too don't appear!
Else this two apps, appear: gmail, bluetooth, edmodo, etc..
So, i tried to do it for other way, "beast way" :D
ImageView Twitter = (ImageView) findViewById(R.id.imageView4);
Twitter.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent browserIntent =
new Intent(Intent.ACTION_VIEW,
Uri.parse("https://twitter.com/intent/tweet?text=https://play.google.com/store/apps/details?id=lol.king%20-%20This%20app%20is%20amazing,%20i%20love%20it!"));
startActivity(browserIntent);
}});
If you read carefully the link and try it (in ur computer) you will see the good results, BUT when i do it in my android phone, it give me the chance to run this link with Twitter App(if you dont have it, will go directly to the link and there will be no problem). And of course when i click it, appear an error: "Twitter has stopped"). Can you help me to tweet Links+texts (or if is impossible to share both, just Link?

android show image in default gallery viewer

I am loading some images into my activity using an AsyncTask as clickable images. On click I need to open that image in the default image viewer of the android. I am new to android. Can any one please help. My code looks like
ImageView image = new ImageView(this);
String ed="http://www.domain.com/image.jpg";
image.setTag(ed);
DownloadImagesTask td=new DownloadImagesTask(this);
td.execute(image);
image.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Log.v("TAGG","sdsd");
}
});
Please help me.
Gallery application does not accept URL for an image as part of the Intent. You need to save the image first. Then you can launch the default image viewer with something like this:
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse("file://" + "/sdcard/test.jpg"), "image/*");
startActivity(intent);

share Fb,Tw and Email using Intent.action_SEND in android

I have to post the text and email to FB,TW and Email.
Here i have created one imageview.if i have to clcik these imageview means the alert dislog box is opening.Here the following 3 item is listed: FB,TW,Email
Here if i have to FB on alert list which means it is go to FB app using action_send...also post the text and image.The other TW and Email app is hide.
If i ahve to click on TW on alert list means it is go to Tw app and post the text and image at the same time hide the FB,Email app...
How can i do ???
pls help me ..i have used below code...here i ahve to clicked Fb means nothing is happened ??? pls give me solution for these...my device installed FB,TW app also...then why nothing is happening ??? pls give me suggestion ??? what's wrong in my code ???
ImageView share = (ImageView) findViewById(R.id.imageView5);
share.setOnClickListener(new OnClickListener()
{
public void onClick ( final View v )
{
final CharSequence[] items =
{
"Facebook", "Twitter", "Email"
};
AlertDialog.Builder builder = new AlertDialog.Builder(SubCate.this);
builder.setTitle("Share Via:");
builder.setItems(items, new DialogInterface.OnClickListener()
{
public void onClick ( DialogInterface dialog , int item )
{
if (items[item] == "Facebook")
{
initShareIntent("facebook");
}
if(items[item] == "Twitter"){
initShareIntent("twitter");
}
if (items[item] == "Email")
{
initShareIntent("gmail");
}
}
});
AlertDialog alert = builder.create();
alert.show();
}
});
}
private void initShareIntent(String type) {
boolean found = false;
Intent share = new Intent(android.content.Intent.ACTION_SEND);
share.setType("image/jpeg");
// gets the list of intents that can be loaded.
List<ResolveInfo> resInfo = getPackageManager().queryIntentActivities(share, 0);
if (!resInfo.isEmpty()){
for (ResolveInfo info : resInfo) {
if (info.activityInfo.packageName.toLowerCase().contains(type) ||
info.activityInfo.name.toLowerCase().contains(type) ) {
share.putExtra(Intent.EXTRA_SUBJECT, _Substring);
share.putExtra(Intent.EXTRA_TEXT, _Substring);
share.putExtra(Intent.EXTRA_STREAM, Uri.parse(_Image));
share.setPackage(info.activityInfo.packageName);
found = true;
break;
}
}
if (!found)
return;
startActivity(Intent.createChooser(share, "Select"));
}
}
EDIT:
Here i have to run the app:
If i have to click Fb means facebook wall is opening...But the text is not displaying here...
If i ahev to click Tw means twitter wall is opening...Twitter text is displayed on wall..But image is couldnot loaded message is displayed ....
If i have to click email means gmail is opening and also displayed the text on subject well...
Why twiiter image couldn't loaded message is displaying...also FB text and image is not displaying ???? pls give me solution for these ????
use SoicalAuth for this functionality its very easy and you do not need create listview and layout for that....
seethis link
In facebook its known issue that user cannot load the text via action send but you can upload the image. and also you can load the text using facebook api.
In twitter also you can send the image as well as text it wont show any problem.
Try with the below code. hope this will help you .
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("image/*");
shareIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
Uri uri = Uri.parse("file://"+combinedFilepath.trim());
String extraString="set";
shareIntent.putExtra(Intent.EXTRA_TEXT,extraString);
shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
shareIntent.putExtra(Intent.EXTRA_TITLE, extraString);
shareIntent.putExtra(Intent.EXTRA_SUBJECT, "app name");
startActivity(Intent.createChooser(shareIntent, "Share via"));

Categories

Resources