How to share text in Instagram - android

I need share text to instagram but I can't use android
intent.putExtra(Intent.EXTRA_TEXT,"MY TEXT");
nothing happen.please help me to do this

Instagram have stopped accepting pre-populated capitions to increase the quality of content in the system. See this post.
http://developers.instagram.com/post/125972775561/removing-pre-filled-captions-from-mobile-sharing

Generic code for sharing text with any social app :
Step1 : Get the package name of app you wanna share :
To get the package name use adb logcat -s ActivityManager this command in windows and run the app like for example you want package name for instagram so run above command and open instagram app you would get the package name in logs
Note : the adb command listed above is for windows .
For ubntu you can use adb logcat | grep "ActivityManager"
STEP 2 : Once you got the package name of app below is generic code for sharing text .
try {
Intent shareOnAppIntent = new Intent();
shareOnAppIntent .setAction(Intent.ACTION_SEND);
shareOnAppIntent .putExtra(Intent.EXTRA_TEXT, getResources().getString(R.string.share_body));
shareOnAppIntent .setType("text/plain");
shareOnAppIntent .setPackage(PACKAGE_NAME_OF_APP);
startActivity(shareOnAppIntent );
} catch (Exception e) {
e.printStackTrace();
Toast.makeText(ShareAppActivity.this, "APP is not installed", Toast.LENGTH_LONG).show();
}

Unfortunately Instagram doesn't receives text from intent. it receives only EXTRA_STREAM object. you can share only images of format jpeg, gif, png. Since they are not providing any SDK you cant share in any other way.
Check Instagram developer documentation here they were clearly mentioning that the accepting Intent Parameter as EXTRA_STREAM
This is the code for sharing photo in Instagram
String type = "image/*";
String filename = "/myPhoto.jpg";
String mediaPath = Environment.getExternalStorageDirectory() + filename;
createInstagramIntent(type, mediaPath);
private void createInstagramIntent(String type, String mediaPath){
// Create the new Intent using the 'Send' action.
Intent share = new Intent(Intent.ACTION_SEND);
// 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 to the Intent.
share.putExtra(Intent.EXTRA_STREAM, uri);
// Broadcast the Intent.
startActivity(Intent.createChooser(share, "Share to"));
}

Here is the intent code to share image and text in Instagram.
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("image/*");
shareIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shareIntent.putExtra(Intent.EXTRA_STREAM,uri);
shareIntent.putExtra(Intent.EXTRA_TEXT,"YOUR TEXT TO SHARE IN INSTAGRAM");
shareIntent.setPackage("com.instagram.android");
return shareIntent;

Related

I want to make android application to send picture, message to instagram users using instagram API

I've tried several sources from Google and GitHub but didn't find any authentic source that could help me sending multiple pictures and posts automatically from my android gallery using the scheduler. Is anyone working with the Instagram API? If so, could you please give me some authentic source?
Instead of using the Instagram API, you can directly start an Intent to post an Image or Video to Instagram by opening a "Share with" dialog. This will require user interaction.
String type = "image/*";
String filename = "/myPhoto.jpg";
String mediaPath = Environment.getExternalStorageDirectory() + filename;
private void createInstagramIntent(String type, String mediaPath){
// Create the new Intent using the 'Send' action.
Intent share = new Intent(Intent.ACTION_SEND);
// 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 to the Intent.
share.putExtra(Intent.EXTRA_STREAM, uri);
// Broadcast the Intent.
startActivity(Intent.createChooser(share, "Share to"));
}
Code example taken from https://www.instagram.com/developer/mobile-sharing/android-intents/

How can i send either an image or a video file using ACTION_SEND?

I want to share either an image or a video file using ACTION_SEND. So basically when the users taps on an image and selects "share image/video" it should send either the image selected or the video selected.
here is my code i am using:
if (filep != null) {
}
File sending=new File(filep);
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_SEND);
intent.setDataAndType(Uri.fromFile(sending),getMimeType(sending.getAbsolutePath()));
intent.putExtra(Intent.EXTRA_STREAM, sending);
startActivity(Intent.createChooser(intent , "Share"));
}
private String getMimeType(String url)
{
String parts[]=url.split("\\.");
String extension=parts[parts.length-1];
String type = null;
if (extension != null) {
MimeTypeMap mime = MimeTypeMap.getSingleton();
type = mime.getMimeTypeFromExtension(extension);
}
return type;
So when testing, it takes me to which app i want to use to share with i.e whatsapp, Facebook, email etc. And then when selecting either one, it then says "sharing failed, please try again." I can't seem to figure out why it doesn't work. However i have the same code to display either image or video file full screen with ACTION_VIEW and that seems to work great but not with sharing.
Can anyone assist please?
EXTRA_STREAM needs to be a Uri, and you are not passing a Uri. Use Uri.fromFile() to construct a Uri.
Also, replace setDataAndType() with setType(), as ACTION_SEND does not use the data aspect of the Intent.

Share intent for instagram in Android

Actually I want to share image in Instagram through intent.
I found this solution for images saved on SD card but I want to do same for image on site (link).
I tried with
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("image/*");
shareIntent
.putExtra(
Intent.EXTRA_STREAM,
Uri.parse("http://www.alliswell.biz/images/products/art/alliswell_signs/yellowB.jpg"));
shareIntent.setPackage("com.instagram.android");
startActivity(shareIntent);
But it's not working.
Edit
When I start above intent it opens my installed Instagram application and it immediately finish Instagram and toast message comes "unable to download file"
Actually it does not parse link and image respectively. What should be issue?
You should use local path to file
For example: "file:///path/to/file/image.png".
Note, that it is very important to include "file" in the path, without this part it also can show the same toast.
First of all you need to download file from that url. you may refer this code for downloading image from url:
String imageUrl = "Your_Image_Url";
if (imageUrl != null && !imageUrl.equals("")) {
String fileName = generateFileNameFromUrl(imageUrl);
String imageLocalPath = Environment.getExternalStorageDirectory()+ File.separator+"Your_App_Name"+ fileName;
if (!new File(imageLocalPath).exists()) {
ImageDownloadModel imageDownloadModel = new ImageDownloadModel();
imageDownloadModel.setImageLocalPath(imageLocalPath);
imageDownloadModel.setImageUrl(imageUrl);
imageDownloadModels.add(imageDownloadModel);
}
ImageLoadAsynkTask imageLoadAsynkTask = new ImageLoadAsynkTask(new ImageDownloadDelegate(), imageDownloadModels, albumDir, activity);
imageLoadAsynkTask.execute();
and then use uri for that image for sharing it on instagram:
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("image/*");
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + imageLocalPath));
shareIntent.setPackage("com.instagram.android");
activity.startActivity(shareIntent);

Attaching video to mms intent fails on specific devices

I had problems attaching a video file (it's always smaller than 100KB) via mms intent. Though this works perfectly well on karbonn A21 (ICS 4.0.4), the attachment fails on HTC one V (ICS 4.0.3) and lg-p920 (2.2.2). I get a toast like "unable to attach video to message"
This is the code I have
Uri uri = Uri.fromFile(videoFile);
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.setType("video/3gp");
sendIntent.setClassName("com.android.mms", "com.android.mms.ui.ComposeMessageActivity");
sendIntent.putExtra("sms_body", "some text here");
sendIntent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(sendIntent);
Any hints/clues/pointers on what I could do would be helpful.
this problem cause because in the video/image need to add to galley:
Read code in
http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android-apps/2.3.3_r1/com/android/mms/ui/ComposeMessageActivity.java
focus in addAttachment part, I saw
String path = c.getString(c.getColumnIndexOrThrow(Images.Media.DATA));
mSrc = path.substring(path.lastIndexOf('/') + 1);
mContentType = c.getString(c.getColumnIndexOrThrow(
mages.Media.MIME_TYPE));
if (TextUtils.isEmpty(mContentType)) {
throw new MmsException("Type of media is unknown.");
})
We saw the message throwed not clear and cause misunderstand.
To solve this, you need to add the file to gallery, pass the URI get from contentResolver.insert to Intent with key Intent.EXTRA_STREAM
One more experience of my when using MMS, the default Activity class use to send MMS change among devices and manufatories, so the setClass com.android.mms.ui.ComposeMessageActivity not always right, it can cause ActivityNotFoundException. When it happends, you must call setPackge("com.android.mms") and remove setClass call.
Hope it help
My approach so far has been to let the user share the video via gmail, youtube and such along with an option to share via mms
ContentValues content = new ContentValues(4);
content.put(Video.VideoColumns.TITLE, "Cool Video");
content.put(Video.VideoColumns.DATE_ADDED,
System.currentTimeMillis() / 1000);
content.put(Video.Media.MIME_TYPE, "video/3gp");
content.put(MediaStore.Video.Media.DATA, videoFile.getAbsolutePath());
ContentResolver resolver = parentActivity.get().getContentResolver();
//I use two URI's. One for the intent with mms(MMSUri) and the
//other(ShareURi) is for sharing video with other social apps like
//gmail, youtube, facebook etc.
Uri ShareUri = resolver.insert(MediaStore.Video.Media.EXTERNAL_CONTENT_URI,content);
Uri MMSUri = Uri.fromFile(videoFile);
List<ResolveInfo> resInfo = getPackageManager().queryIntentActivities(sendIntent, 0);
if(!resInfo.isEmpty())
{
for (ResolveInfo resolveInfo : resInfo)
{
String packageName = resolveInfo.activityInfo.packageName;
Intent targetIntent = new Intent(Intent.ACTION_SEND);
targetIntent.setType("video/3gp");
targetIntent.setPackage(packageName);
if(packageName.contains("mms"))
{
targetIntent.putExtra("sms_body", "Some text here");
targetIntent.putExtra(Intent.EXTRA_STREAM, MMSUri);
}
else
{
targetIntent.putExtra(Intent.EXTRA_SUBJECT, "I can has videos?");
targetIntent.putExtra(Intent.EXTRA_TITLE, "Some title here");
targetIntent.putExtra(Intent.EXTRA_TEXT,"You have gots to watch this");
targetIntent.putExtra(Intent.EXTRA_STREAM, ShareUri);
}
targetedIntents.add(targetIntent);
}
Intent chooserIntent = Intent.createChooser(targetedIntents.remove(0), "Select app to share");
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, targetedIntents.toArray(new Parcelable[]{}));
startActivity(chooserIntent);
return;
}
Toast.makeToast(this, "No intents found for this action", Toast.LENGTH_SHORT, Gravity.CENTER).show();
I try to populate my own target intents for the Intent.createChooser knowing only these would work in attaching/uploading my video
EDIT: I wont be accepting my own answer as the right one. I'm most optimistic there's a better one out there

How to send a picture via email in Android, previewed but NOT attached..?

I want to send a picture preview in my mail Intent.
I dont want to attach it, i just want it to be shown.
This is my intent:
String textToSend = getString(R.string.mailHi)+"<br><br>"+getString(R.string.mailText)+getTextToSendViaMail();
Uri pngUri = null;
File currentShopImage = new File(Environment.getExternalStorageDirectory().toString()+"/OpenGuide/"+Integer.toString(keyId)+"_1_normal.pn_");
if(currentShopImage.exists()){
File pngFile = new File(currentShopImage.toString());
pngUri = Uri.fromFile(pngFile);
}
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("text/plain");
//i.putExtra(Intent.EXTRA_EMAIL, new String[] { emailCim });
i.putExtra(Intent.EXTRA_SUBJECT, "OpenGuide");
i.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(textToSend));
if(pngUri!= null)
i.putExtra(Intent.EXTRA_STREAM, pngUri);
try {
startActivity(Intent.createChooser(i, getString(R.string.SendMail)));
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(ShopActivity.this, getString(R.string.MailClientNotFound), Toast.LENGTH_SHORT).show();
}
How can i achive such a thing ?
As far as I understood your problem, you want to place the image inside the mail with other text. In the words of Email protocol it's called an INLINE Attachment.
You would not be able to do this with intents as none of the email clients installed on the device supports creating html messages.
If it's really a core part of your app, you should consider a third party api to do this. One of the such library is JavaMail. You would be able to send html messages through this library but will take some time in setting up.
Here's a link that may give you some hint, how it's done.
Then you need to send a HTML generated email afaik.

Categories

Resources