I'm developing a social networking app and our users can connect their Instagram account to our service. I'd like to open Instagram profiles directly in their official Android app (if it is installed) but I can't find any way to do that. However, there is a page on their developer site about the exact same feature on iOS but this doesn't seem to work on Android at all. Everything I found on the web only suggests various ways to open links in a browser. Any suggestions?
-
@kentarosu yes, but there is no correct answer. – Grishka Feb 02 '14 at 10:38
-
Read the comments of the answer chosen as correct. It says you can't open the IG app at this point to a profile, only to a picture. The closest solution is to open the browser. – gatlingxyz Feb 02 '14 at 15:48
8 Answers
I solved this problem using the following code.
Uri uri = Uri.parse("http://instagram.com/_u/xxx");
Intent likeIng = new Intent(Intent.ACTION_VIEW, uri);
likeIng.setPackage("com.instagram.android");
try {
startActivity(likeIng);
} catch (ActivityNotFoundException e) {
startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse("http://instagram.com/xxx")));
}
-
7
-
4Look at this answer: https://stackoverflow.com/questions/15497261/open-instagram-user-profile You must use ``/_u/`` format for profiles – Gonzalo Aug 22 '17 at 19:17
-
2@IharobAlAsimi It's very basic Android code. Not everything needs explanation. – zundi Jan 16 '18 at 00:04
Although @jhondge's solution works and is correct. This is a more cleaner way to do this:
Uri uri = Uri.parse("http://instagram.com/_u/xxx");
Intent insta = new Intent(Intent.ACTION_VIEW, uri);
insta.setPackage("com.instagram.android");
if (isIntentAvailable(mContext, insta)){
startActivity(insta);
} else{
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://instagram.com/xxx")));
}
private boolean isIntentAvailable(Context ctx, Intent intent) {
final PackageManager packageManager = ctx.getPackageManager();
List<ResolveInfo> list = packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
return list.size() > 0;
}

- 3,437
- 1
- 34
- 48
-
I like this solution, but for some reason it does not work for me when I try to do the exact same thing for a Facebook Intent. The try/catch approach works for Facebook though, and your approach is fine for an Instagram Intent. Do you by chance know what could cause this? – Krøllebølle Feb 05 '16 at 17:16
-
@Krøllebølle I think I faced the same issue and switched to try catch for facebook. Don't know what causes this. – Rahul Sainani Feb 09 '16 at 16:51
-
This works for me... I Tried it in Android Emulator without Instagram app it opened in the browser and I tried it in my Mobile in which Instagram is installed and it opened the Instagram app. Thank You. – Ramesh Aug 16 '19 at 21:24
To open directly instagram app to a user profile :
String scheme = "http://instagram.com/_u/USER";
String path = "https://instagram.com/USER";
String nomPackageInfo ="com.instagram.android";
try {
activite.getPackageManager().getPackageInfo(nomPackageInfo, 0);
intentAiguilleur = new Intent(Intent.ACTION_VIEW, Uri.parse(scheme));
} catch (Exception e) {
intentAiguilleur = new Intent(Intent.ACTION_VIEW, Uri.parse(path));
}
activite.startActivity(intentAiguilleur);
// Use this link to open directly a picture
String scheme = "http://instagram.com/_p/PICTURE";

- 161
- 1
- 3
I tried this way and it worked for me..
instabtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent instaintent = getActivity().getPackageManager().getLaunchIntentForPackage("com.instagram.android");
instaintent.setComponent(new ComponentName( "com.instagram.android", "com.instagram.android.activity.UrlHandlerActivity"));
instaintent.setData( Uri.parse( "https://www.instagram.com/_u/bitter_truth_lol") );
startActivity(instaintent);
}
});

- 13,409
- 16
- 61
- 96
Based on @alex-karapanos answer, I use this code:
fun launchInsta() {
val uriForApp: Uri = Uri.parse("http://instagram.com/_u/xxx")
val forApp = Intent(Intent.ACTION_VIEW, uriForApp)
val uriForBrowser: Uri = Uri.parse("http://instagram.com/xxx")
val forBrowser = Intent(Intent.ACTION_VIEW, uriForBrowser)
forApp.component =
ComponentName(
"com.instagram.android",
"com.instagram.android.activity.UrlHandlerActivity"
)
try {
startActivity(forApp)
} catch (e: ActivityNotFoundException) {
startActivity(forBrowser)
}
}

- 1,399
- 1
- 15
- 36
Kotlin Version of @jhondge answer:
val uriForApp: Uri = Uri.parse("http://instagram.com/_u/xxx")
val forApp = Intent(Intent.ACTION_VIEW, uriForApp)
val uriForBrowser: Uri = Uri.parse("http://instagram.com/xxx")
val forBrowser = Intent(Intent.ACTION_VIEW, uriForBrowser)
forApp("com.instagram.android")
try {
startActivity(context, forApp, null)
} catch (e: ActivityNotFoundException) {
startActivity(context, forBrowser, null)
}

- 895
- 2
- 7
- 20
I implemented this using fragment in webview but I have one issue, the instagram pop up comes three times :
webView.setWebViewClient(new WebViewClient()
{
public boolean shouldOverrideUrlLoading(WebView viewx, String urlx)
{
if(Uri.parse(urlx).getHost().endsWith("instagram.com")) {
gotoinstagram();
return false;
}
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(urlx));
viewx.getContext().startActivity(intent);
return true;
}
});
outside of onCreateView
public void gotoinstagram()
{
Uri uri = Uri.parse("http://instagram.com/_u/XXXX");
Intent likeIng = new Intent(Intent.ACTION_VIEW, uri);
likeIng.setPackage("com.instagram.android");
try {
startActivity(likeIng);
} catch (ActivityNotFoundException e) {
startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse("http://instagram.com/XXXX")));
}
}

- 2,953
- 6
- 34
- 54

- 21
- 4
A number of people already answered this question but still I am answering. Using the method answered above the workflow is go through 3 steps.
Step1: The app parse uri and intent
Step2: The intent go to browser and load Instagram url
Step3: Browser then redirect to Instagram App
But to open Instagram app directly without going to Browser you can use the method mentioned below. Create an Intent method like below:-
private Intent instaIntn(Context context) {
Intent i1;
String instaId = "your insta id";
String appResolver = "instagram://user?username=";
String webResolver = "https://instagram.com/";
String instaPackageName = "com.instagram.android";
String instaLitePackName = "com.instagram.lite";
try {
context.getPackageManager().getPackageInfo(instaPackageName, 0);
i1 = new Intent(Intent.ACTION_VIEW, Uri.parse(appResolver+instaId));
} catch (PackageManager.NameNotFoundException e1) {
Toast.makeText(getApplication(), "Instagram not found", Toast.LENGTH_SHORT).show();
try {
context.getPackageManager().getPackageInfo(instaLitePackName, 0);
i1 = new Intent(Intent.ACTION_VIEW, Uri.parse(appResolver+instaId));
} catch (PackageManager.NameNotFoundException e2) {
Toast.makeText(getApplication(), "Instagram and instagram lite not found", Toast.LENGTH_SHORT).show();
i1 = new Intent(Intent.ACTION_VIEW, Uri.parse(webResolver+instaId));
}
}
return i1;
}
Now you can Start this intent from anywhere inside class by simply calling below statement:-
startActivity(instaIntn(getApplicationContext()));
Now what it will do, it will try to open Instagram app, if instagram app is not installed then it will try to open Instagram lite. If both app is missing then it will intent to browser. The above method intent user to Instagram app and user profile. You can also intent user to Instagram image video and other page. See full documentation in here https://developers.facebook.com/docs/instagram/sharing-to-feed/

- 75
- 8