Android: send image and text to Instagram

How can I send image and text to instagram? not a problem if I have to open an instagram application, or if I do it via api or another. the problem is that I can not find how: they only have an iphone hook, and api is not applicable. did someone do this or know? thanks.

+2
source share
3 answers

I doubt Instagram developers will ever release the iPhone as hooks for android, since Intents already serve this purpose.

If you want to share the image of your application, use this intention:

Intent i = new Intent(Intent.ACTION_SEND); i.setType("image/jpeg"); i.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///sdcard/Path/To/Image.jpg")); startActivity(Intent.createChooser(i, "Share Image")); 

Please note that this will show a dialog allowing the user to choose which photo-sharing application launches.

+5
source

Try it, it worked for me. I will use it to exchange information about my product. I get the product details, such as name, image, description from the server and display in the application, and then transfer it to instagram.

Get the URL of the image from the server.

 URL url = ConvertToUrl(imgURL); Bitmap imagebitmap = null; try { imagebitmap = BitmapFactory.decodeStream(url.openConnection() .getInputStream()); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } 

Post image and text on instagram.

 // post on instagram Intent shareIntent = new Intent( android.content.Intent.ACTION_SEND); shareIntent.setType("image/*"); shareIntent.putExtra(Intent.EXTRA_STREAM, getImageUri(HomeActivity.this, result)); shareIntent.putExtra(Intent.EXTRA_SUBJECT, sharename); shareIntent.putExtra( Intent.EXTRA_TEXT, "Check this out, what do you think?" + System.getProperty("line.separator") + sharedescription); shareIntent.setPackage("com.instagram.android"); startActivity(shareIntent); 

Convert Uri string to URL

 private URL ConvertToUrl(String urlStr) { try { URL url = new URL(urlStr); URI uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath(), url.getQuery(), url.getRef()); url = uri.toURL(); return url; } catch (Exception e) { e.printStackTrace(); } return null; 

}

Convert Bitmap to Uri

 public Uri getImageUri(Context inContext, Bitmap inImage) { ByteArrayOutputStream bytes = new ByteArrayOutputStream(); inImage.compress(Bitmap.CompressFormat.JPEG, 100, bytes); String path = MediaStore.Images.Media.insertImage( inContext.getContentResolver(), inImage, "Title", null); return Uri.parse(path); 

}

+5
source

This works for me .... but it suggests the name of the package com.instagram.android, which may change without warning. I believe.

 private void shareToInstagram(Uri imageUri){ Intent i = new Intent(Intent.ACTION_SEND); i.setType("image/*"); i.putExtra(Intent.EXTRA_STREAM, imageUri); i.setPackage("com.instagram.android"); activity.startActivity(i); } 

You can always check if the com.instagram.android package is installed using getPackageManager () ... and if not, do not set the package name in the intent and do not let the application select the user the application to share the image with.

+4
source

Source: https://habr.com/ru/post/1498936/


All Articles