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

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/

Related

Android Intent to open instagram posting view

How to open Instagram app in posting mode (so the same view we get after clicking plus at home screen within Instagram app)? I've seen android apps which are doing that, however wasn't able to find information explaing how to achieve it.
That code works for opening the home view:
Uri uri = Uri.parse("http://instagram.com/");
Intent likeIng = new Intent(Intent.ACTION_VIEW, uri);
likeIng.setPackage("com.instagram.android");
startActivity(likeIng);
Perhaps there is some other uri which could work?
After a bit of research it turned out that deep linking with 'instagram://share' opens the desired view.
You can do that only when you have a media to share on Instagram:
try {
String type = "image/*";
String filename = "/myPhoto.jpg";
String mediaPath = Environment.getExternalStorageDirectory() + filename;
Intent share = new Intent(Intent.ACTION_SEND);
share.setPackage("com.instagram.android");
share.setType(type);
File media = new File(mediaPath);
Uri uri = null;
share.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(share);
} catch (Exception e) {
e.printStackTrace();
}
You can create a fake media though to be able to use this method.
Just to expand on #Paavo answer to show the answer in code.
Uri uri = Uri.parse("instagram://share");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
intent.setPackage("com.instagram.android");
//Check that the user can open the intent, meaning they have the Instagram app installed
if (getPackageManager().resolveActivity(intent, 0) != null)
startActivity(intent);
else //User doesn't have app installed, handle however you want
throw new Resources.NotFoundException();

how to share images inside assets folder with intent to other application

i want to share images inside an assets folder using intent to the following applications
hangout
whatsapp
line chat
viber
tango
wechat
i have try this code for whatsapp but it given me file not supported
public void share (){
String file = "file:///android_asset/food/apple.png";
Uri filePath = Uri.fromFile(new File("content://com.example.zainabishaqmusa.postemoji/assets/gestures/aok.png"));
final ComponentName name = new ComponentName("com.whatsapp", "com.whatsapp.ContactPicker");
Intent oShareIntent = new Intent();
oShareIntent.setComponent(name);
//oShareIntent.setType("text/plain");
//oShareIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Website : www.google.com");
oShareIntent.putExtra(Intent.EXTRA_STREAM, filePath);
oShareIntent.setType("image/png");
oShareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
Gesture.this.startActivity(oShareIntent);
}
You would need a ContentProvider that is capable of sharing content from assets. My StreamProvider offers this, or you could write your own.

Android Intent share Image from url path without saving in local

Hi I need to share image using intent the image is stored in server path ho to achieve it
private void shareContent(String urlpath)
{
URL url = null; //Some instantiated URL object
try {
url = new URL(urlpath);
URI uri = url.toURI();
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
URI screenshotUri = uri;
sharingIntent.setType("image/*");
sharingIntent.putExtra(Intent.EXTRA_STREAM, screenshotUri);
context.startActivity(Intent.createChooser(sharingIntent, "Share image using"));
} catch (Exception e) {
e.printStackTrace();
}
}
This is the method that I am using when share button is clicked and I am working in this list adapter
The documentation for EXTRA_STREAM states that the value needs to be a content URI. Technically nothing is stopping you from putting a http URI there. But 99% of receiving apps won't support that.
What you could do is write a ContentProvider that accesses the contents of a http URI and streams them to the receiving application. Kind of like FileProvider, but for http URIs instead of files.
Or, prior to sharing, you download the image, write it to a local file and expose it using FileProvider.

How to share text in Instagram

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;

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.

Categories

Resources