share Fb,Tw and Email using Intent.action_SEND in android - 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"));

Related

Share button in android app [duplicate]

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.

I want on clicking the button it should invoke Facebook app to share it android

I have created an greeting card using textview and imageview, and used one button at the bottom, now I want on clicking that button it should invoke Facebook app to share it.I am using this code,correct me plz.
public void onFacebookButtonClicked(View view){
String url = "https://www.facebook.com";
Intent facebookIntent = new Intent(Intent.ACTION_SEND);
facebookIntent.setData(Uri.parse(url));
facebookIntent.setType("text/plain");
facebookIntent.setPackage(url);
facebookIntent.putExtra(Intent.EXTRA_TEXT, url);
if (facebookIntent.resolveActivity(getPackageManager()) != null) {
startActivity(facebookIntent);
}
}

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 App to Send Images Via Email

Ok once again, I am in way over my head here while learning android. After finally developing my simple little app, I am trying to use some of the benefits of having a native app.
So, project one, make a page which can send images via email (either from the gallery or camera)
Essentially its a select and send via email, but I don't even know where to start.
I found some code that somebody else was asking about at;
Android App Take/ Email Photo
I tried this, but get all sorts of errors from eclipse, replating to downloadedPic section.
If somebody could please take a look and advise me on the best way to do this, that would be amazing. As usual sorry for my beginers stupidity, but I guess everyone has to learn somewhere
THIS IS MY .JAVA AT PRESENT
public class Photos extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_photos);
getActionBar().setDisplayHomeAsUpEnabled(true);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_photos, menu);
return true;
}
THIS IS MY .XML AT PRESENT
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Please chose the options below to select and upload photos into the
DCC for the selected project..."
tools:context=".Photos"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
First what should you do is get the image storage path by using the file,
File *photo = new File(Environment.getExternalStorageDirectory()+"/Android/data/"+getApplicationContext().getPackageName()+"/Fault", imagename+".png");
Then Convert that file path in to Uri
Uri imageuri = Uri.fromFile(photo);
Finally send it the image via email using your imageuri
Intent send_report = new Intent(Intent.ACTION_SEND);
send_report.putExtra(Intent.EXTRA_EMAIL, new String[]{ email_emailid});
send_report.putExtra(Intent.EXTRA_SUBJECT, email_subject);
send_report.putExtra(Intent.EXTRA_STREAM, imageuri);
send_report.putExtra(Intent.EXTRA_TEXT, email_body);
send_report.setType("text/plain");
send_report.setType("image/png");
startActivityForResult(Intent.createChooser(send_report, "Choose an Email client"), 77);
Hope it helps.
Get Your Image First :
// Get Image form mnt/sdcard/YOUR_FLODER/my_image.png
ImageView my_Image = (ImageView)findViewById(R.id.my_Image);
Imagepath="/sdcard/YOUR_FLODER/"+my_iamge+".png";
bitmap = BitmapFactory.decodeFile(Imagepath);
Fetch mail address:
// This Will fetch merchant's Email id from Deivce.
Pattern emailPattern = Patterns.EMAIL_ADDRESS; // API level 8+
AccountManager manager =(AccountManager)getSystemService(ACCOUNT_SERVICE);
//Account[] accounts = AccountManager.get(getApplicationContext()).getAccounts();
Account[] accounts = manager.getAccounts();
for (Account account : accounts)
{
if (emailPattern.matcher(account.name).matches())
{
possibleEmail = account.name;
}
}
Send Click Event :
Intent i = new Intent(android.content.Intent.ACTION_SEND);
i.setType("image/png");
i.putExtra(Intent.EXTRA_CC,new String[]{possibleEmail});
i.putExtra(android.content.Intent.EXTRA_SUBJECT, "Mail With Image attachment");
startActivity(Intent.createChooser(i2, "Send Email..."));
At The End Photos.java
public class Photos extends Activity
{
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.Activity_Photos);
// your image fetching code
// fetch mail code
// write button click event
// put intent code in click event
}
}
So Hope Now you Get Full Code.

Categories

Resources