Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: post image and text to Instagram

How can i post an image and a text to instagram? no problem if i must open the instagram app, or if i do via api or other. the problem is that i can't find how to: they have the iphone hook only, and the api is incomprensible. someone have did that, or have the know? thanks.

like image 796
Zak Avatar asked Dec 04 '22 15:12

Zak


1 Answers

Try this it is worked for me. I will use it for share my product details. i will get details of product like name,image,description from the server and display in app and then share it to instagram.

Get image url from 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);
}
like image 64
Jaydip Meghapara Avatar answered Jan 02 '23 13:01

Jaydip Meghapara