Here is how we can share an image with a text message on Instagram using Share Dialog. There is no need to use any Instagram API's.
The package name for Instagram on Android store is com.instagram.android
Uri file = Uri.parse("android.resource://com.code2care.yourpackage/"+R.drawable.YOUR_IMAGE_HERE);
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("image/*");
shareIntent.putExtra(Intent.EXTRA_STREAM,file);
shareIntent.putExtra(Intent.EXTRA_TITLE, "YOUR TEXT HERE");
shareIntent.setPackage("com.instagram.android");
startActivity(shareIntent);
Example:
package com.code2care.sendInstaIntentExample;
import gesture.SwipeDetector;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MotionEvent;
import android.widget.TextView;
public class SwipeDemo extends Activity {
private TextView textview;
private SwipeDetector sd;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_swipe_demo);
Uri file = Uri.parse("android.resource://com.code2care.myApp/"+R.drawable.MY_IMAGE_TO_SHARE);
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("image/*");
shareIntent.putExtra(Intent.EXTRA_STREAM,file);
shareIntent.putExtra(Intent.EXTRA_TITLE, "YOUR TEXT HERE");
shareIntent.setPackage("com.instagram.android");
tartActivity(shareIntent);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.swipe_demo, menu);
return true;
}
@Override
public boolean onTouchEvent(MotionEvent me) {
return sd.onTouch(null, me);
}
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
super.dispatchTouchEvent(ev);
return sd.onTouchEvent(ev);
}
}
Have Questions? Post them here!
More Posts related to android,
- appcompat_v7 errors after updates to API level 21 Material Theme
- adb: The Android Debug Bridge and Commands
- The Android Virtual Device myEmulator is currently running an emulator and cannot be deleted.
- How to make TextView Text Transparent [Android]
- Android is starting optimizing... app 1 of 1
- How to make Text in TextView bold and italic in Android
- Android Development - How to switch between two Activities
- Android : IOException: Unable to open sync connection!
- Android Toolbar example with appcompat_v7 21
- How to Change Android Title Bar Color?
- How to Add Padding to Android TextView
- JavaScript : redirect page to other url
- Programmatically Send an Email from Android App using Intent
- What is Android Toast.LENGTH_SHORT and Toast. LENGTH_LONG durations
- [Soluiton] You already have the latest version of Android Studio installed
- Detect swipes on Android Activity
- Add Buttons at the bottom of Android Layout xml file
- Android Lint app_name is not translated in af (Afrikaans) am (Amharic) ar (Arabic) bg (Bulgarian)
- Hide Navigation Bar from Android Screen Activity
- Android Disable EditText from Auto Focus on Activity load
- Toast not getting displayed Android App
- How to Enable Developers Option in Android Phones Settings
- Android : Duplicate registration for activity com.example.abc
- Android ListView turns Black or Flickers while Scrolling
- Android Studio Ctrl Shift o auto import not working
More Posts:
- How to shuffle lines randomly in Sublime Text - Sublime-Text
- How to save All Files at once in Notepad++ - NotepadPlusPlus
- reCAPTCHA Implementation Tutorial - CSS
- How to convert an int to a string in Python - Python
- Java XML-RPC 3.1.x based web service example - Java
- Fix: Administrative Privileges Required Error Code: 0-2005 (1223) - Windows-11
- 35: Python Program to find the System Hostname - Python-Programs
- How to install Microsoft Outlook App on Mac - MacOS