How to send drawable to twitter intent in android - android

I have made an android app ,I want to share a drawable to twitter,Currently I have done this way for text,But can any buddy tell me how to attach image to intent to share via twitter ,Thank you in advance,My code is as below:
public void shareTwitterIntent() {
String tweetUrl = "https://twitter.com/intent/tweet?text=3SManiquines";
Uri uri = Uri.parse(tweetUrl);
startActivity(new Intent(Intent.ACTION_VIEW, uri));
}

Try this (from How to attach a Bitmap when launching ACTION_SEND intent -- perhaps a duplicate?):
String pathofBmp = Images.Media.insertImage(getContentResolver(), bitmap,"title", null);
Uri bmpUri = Uri.parse(pathofBmp);
final Intent emailIntent1 = new Intent( android.content.Intent.ACTION_SEND);
emailIntent1.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
emailIntent1.putExtra(Intent.EXTRA_STREAM, bmpUri);
emailIntent1.setType("image/png");

Related

Share Image in Twitter in Android using Intent

Hello I try to use the share dialog using Intent with the code below. I want to share an image and text at the same time. However I get the eror: Failed to insert image java.io.FileNotFoundException: No such file or directory
My code is as below, am I doing anything wrong. The code is in a fragment class.
Bitmap image = bmResized;
String pathOfBmp = Images.Media.insertImage(getActivity().getContentResolver(), image, "twitter_image.jpg", null);
Uri bmpUri = Uri.parse(pathOfBmp);
Intent tweetIntent = new Intent(Intent.ACTION_SEND);
tweetIntent.setAction(Intent.ACTION_SEND);
tweetIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
tweetIntent.putExtra(Intent.EXTRA_TEXT, "here is the tweet text");
tweetIntent.putExtra(Intent.EXTRA_STREAM, bmpUri);
tweetIntent.setType("image/jpeg");
startActivity(Intent.createChooser(tweetIntent, "Share this via"));
You can look Fabric library. For twitter process usually using Fabric library.
You can look Fabric document:
https://docs.fabric.io/android/twitter/compose-tweets.html
Also this is github link:
https://github.com/fabric/fabric
Try this:
Drawable mDrawable = mImageView.getDrawable();
Bitmap mBitmap = ((BitmapDrawable) mDrawable).getBitmap();
String path = MediaStore.Images.Media.insertImage(getContentResolver(), mBitmap, "Image Description", null);
Uri uri = Uri.parse(path);
Intent tweetIntent = new Intent(Intent.ACTION_SEND);
tweetIntent.setType("image/jpeg");
tweetIntent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(tweetIntent, "Share this via"));

How to customize the built-in chooser(dialogue box) of share intent?

Is there any way to customize the createChooser of share intent in startActivity(Intent.createChooser(i,"Share via"));?
Showing the apps not in a dialogue box maybe in scroll view as buttons
String urlToShare = "www.google.com"
code to share link twitter
try {
Intent shareIntent = ShareCompat.IntentBuilder.from(getParent())
.setType("text/plain")
.setText("Sharing text with image link \n "+urlToShare).setStream(null)
.getIntent()
.setPackage("com.twitter.android");
startActivity(shareIntent);
} catch (Exception e) {
// If we failed (not native FB app installed), try share through SEND
Intent intent = new Intent(Intent.ACTION_SEND);
String sharerUrl = "https://twitter.com/intent/tweet?text=" + urlToShare;
intent = new Intent(Intent.ACTION_VIEW, Uri.parse(sharerUrl));
startActivity(intent);
}
code to share link google plus
try {
Intent shareIntent = ShareCompat.IntentBuilder.from(getParent())
.setType("text/plain")
.setText("Sharing text with image link \n "+urlToShare).setStream(null)
.getIntent()
.setPackage("com.google.android.apps.plus");
startActivity(shareIntent);
} catch (Exception e) {
// If we failed (not native FB app installed), try share through SEND
Intent intent = new Intent(Intent.ACTION_SEND);
String sharerUrl = "https://plus.google.com/share?url=" + urlToShare;
intent = new Intent(Intent.ACTION_VIEW, Uri.parse(sharerUrl));
startActivity(intent);
}
code to share link whatsapp
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_TEXT, urlToShare);
intent.setType("text/plain");
intent.setPackage("com.whatsapp");
startActivity(intent);
Yes you can do it by getting the share options as activities and pass them to your adapter, i am posting a sample code
Intent sendIntent = new Intent(android.content.Intent.ACTION_SEND);
sendIntent.setType("text/plain");
List activities = this.getPackageManager().queryIntentActivities(sendIntent, 0);
By this you will get share Intents in activities object and then you can convert it to Object Array some thing like this
Objects[] item = activities.toArray();
for( int i=0; i<item.length; i++ ) {
ResolveInfo infoName = (ResolveInfo) items[i];
String name = info.activityInfo.name;
Drawable logo = info.loadIcon(context.getPackageManager());
// Set them to your Views
}
and when your view is clicked and you want to perform the share functionality you will do some thing like this
ResolveInfo info = (ResolveInfo) item(position);
Intent intent = new Intent(android.content.Intent.ACTION_SEND);
intent.setClassName(info.activityInfo.packageName, info.activityInfo.name);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_SUBJECT, "Your Subject");
intent.putExtra(Intent.EXTRA_TEXT, "Your Text");
startActivity(intent);
this is what i have done to share link and image to another apps something like this just try
/*
* Method to share either text or URL.
*/
private void shareTextUrl() {
Intent share = new Intent(android.content.Intent.ACTION_SEND);
share.setType("text/plain");
share.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
// Add data to the intent, the receiving app will decide
// what to do with it.
share.putExtra(Intent.EXTRA_SUBJECT, "Title Of The Post");
share.putExtra(Intent.EXTRA_TEXT, "http://www.google.com");
startActivity(Intent.createChooser(share, "Share link!"));
}
/*
* Method to share any image.
*/
private void shareImage() {
Intent share = new Intent(Intent.ACTION_SEND);
// If you want to share a png image only, you can do:
// setType("image/png"); OR for jpeg: setType("image/jpeg");
share.setType("image/*");
// Make sure you put example png image named myImage.png in your
// directory
String imagePath = Environment.getExternalStorageDirectory()
+ "/myImage.png";
File imageFileToShare = new File(imagePath);
Uri uri = Uri.fromFile(imageFileToShare);
share.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(share, "Share Image!"));
}

Android Share Intent changing PNG to JPG

I'm trying to share an image of type PNG using G-mail. But in mail attachment I'm getting JPG.
final Bitmap selectedRowToBmp = BitmapFactory.decodeResource(getResources(), R.drawable.share_image);
if (selectedRowToBmp != null) {
String pathofBmp = Images.Media.insertImage(hostActivity.getContentResolver(), selectedRowToBmp, null, null);
Uri bmpUri = Uri.parse(pathofBmp);
final Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("image/png");
shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shareIntent.putExtra(Intent.EXTRA_STREAM, bmpUri);
}
Any Help will be appreciated.

photo share intent in android

Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
shareIntent.setType("image/*");
Uri uri = Uri.parse(pathToImage);
shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
return shareIntent;
i was used above code for sharing image on social sites.when i posting image on facebook only text is posted and image is not coming.how can we get the image and pathtoimage is string variable i am getting sever image path and stored in string variable.but it is not working.please give any solutions for my above question.?
Try this
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"));
Refer more links
http://android-developers.blogspot.in/2012/02/share-with-intents.html
Android Share Via Dialog
Image post into facebook wall from android sdcard
This is the solution I came up with:
This function allows you to share to instagram, facebook or any other app if you know the package name. If the app is not installed it redirects to the Play Store. If you send "others" as parameters, you will display a list of apps that also support image sharing.
shareImageIntent(mActivity,"image/*", "/storage/emulated/0/Pictures/Instagram/IMG_20150120_095603.jpg", "Instagram Sharing test. #Josh","com.instagram.android"); // parameters - for facebook: "com.facebook.katana" , to display list of other apps you can share to: "others"
public void shareImageIntent(Activity a,String type, String mediaPath, String caption, String app){
Intent intent = mContext.getPackageManager().getLaunchIntentForPackage(app);
if ((intent != null)||(app.equals("others"))){
// Create the new Intent using the 'Send' action.
Intent share = new Intent(Intent.ACTION_SEND);
if(!app.equals("others"))
share.setPackage(app);
// 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 and the caption to the Intent.
share.putExtra(Intent.EXTRA_STREAM, uri);
share.putExtra(Intent.EXTRA_TEXT, caption);
// Broadcast the Intent.
//startActivity(Intent.createChooser(share, "Share to"));
a.startActivity(share);
}
else{
intent = new Intent(Intent.ACTION_VIEW);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//intent.setData(Uri.parse("market://details?id="+"com.instagram.android"));
intent.setData(Uri.parse("market://details?id="+app));
a.startActivity(intent);
}
}
You can not use Intent to post to Facebook. They have specifically blocked this. You have to either use their SDK or copy it to the clipboard and have the user paste it after the facebook interface opens. I am having this same problem.

How to send MMS from Android App?

I am working on a project where I need to send MMS from my android app. Below is the code which I tried but it is not working. Please advise.
Intent mmsIntent = new Intent(Intent.ACTION_SENDTO);
mmsIntent.addCategory(Intent.CATEGORY_DEFAULT);
mmsIntent.setType("vnd.android-dir/mms-sms");
mmsIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));//Uri.parse(url));
mmsIntent.setData(Uri.parse("sms:" + "89565656"));
startActivity(mmsIntent);
check this:
Intent i = new Intent(Intent.ACTION_SEND);
i.putExtra("address","9876543211");
i.putExtra("sms_body","hello..");
i.putExtra(Intent.EXTRA_STREAM,Uri);
i.setType("image/png");
startActivity(i);
Here Uri is:
Uri uri = Uri.parse("content://media/external/images/media/1");
or
Uri uri = Uri.parse("file://mnt/sdcard/test.jpg");
or
Uri uri = Uri.parse("file://"+Environment.getExternalStorageDirectory()+"/test.jpg");
For me below code is working perfect.....
Intent smsIntent = new Intent(android.content.Intent.ACTION_SEND);
smsIntent.putExtra("sms_body", mContext.getString(R.string.app_name));
smsIntent.putExtra(Intent.EXTRA_STREAM,Uri.parse("file://" + imagePath));
smsIntent.setType("image/png");
mContext.startActivity(smsIntent);

Categories

Resources