I managed to open the Twitter and Facebook user profile from my app. But I can not find any references to Instagram.
Is There a way to open Instagram in order to show a user profile like in twitter or facebook?
For instance, in order to get the Intent to launch the twitter application I do:
public Intent getOpenTwitterIntent(Context context) {
try {
return new Intent(Intent.ACTION_VIEW,
Uri.parse("twitter://user?screen_name="
.concat(twitterUsername)));
} catch (Exception e) {
return new Intent(
Intent.ACTION_VIEW,
Uri.parse("https://twitter.com/#!/".concat(twitterUsername)));
}
}
How can I achive something similar with Instagram?
Thanks in advance.
Here is a method to get the Intent to open the Instagram app to the user's profile page:
/**
* Intent to open the official Instagram app to the user's profile. If the Instagram app is not
* installed then the Web Browser will be used.</p>
*
* Example usage:</p> {#code newInstagramProfileIntent(context.getPackageManager(),
* "http://instagram.com/jaredrummler");}</p>
*
* #param pm
* The {#link PackageManager}. You can find this class through
* {#link Context#getPackageManager()}.
* #param url
* The URL to the user's Instagram profile.
* #return The intent to open the Instagram app to the user's profile.
*/
public static Intent newInstagramProfileIntent(PackageManager pm, String url) {
final Intent intent = new Intent(Intent.ACTION_VIEW);
try {
if (pm.getPackageInfo("com.instagram.android", 0) != null) {
if (url.endsWith("/")) {
url = url.substring(0, url.length() - 1);
}
final String username = url.substring(url.lastIndexOf("/") + 1);
// http://stackoverflow.com/questions/21505941/intent-to-open-instagram-user-profile-on-android
intent.setData(Uri.parse("http://instagram.com/_u/" + username));
intent.setPackage("com.instagram.android");
return intent;
}
} catch (NameNotFoundException ignored) {
}
intent.setData(Uri.parse(url));
return intent;
}
So far I couldn't find a way to show user's profile directly.. but there is a way around..
Found this solution from Instagram Manifest from GitHub
Intent iIntent = getPackageManager().getLaunchIntentForPackage("com.instagram.android");
iIntent.setComponent(new ComponentName( "com.instagram.android", "com.instagram.android.activity.UrlHandlerActivity"));
iIntent.setData( Uri.parse( "http://instagram.com/p/gjfLqSBQTJ/") );
startActivity(iIntent);
This will open particular image post by the user in the app. From the page app user can open the profile with the link inside.
If you want to open recent post or something , you can use Instagram API
This is not we want exactly , but the better option now... i guess :)
After a brief search and trying what we all know "WON'T WORK" I got this to work
Uri uri = Uri.parse("http://instagram.com/mzcoco2you");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
This should start your default browser and ... there you go. The answer is "instagram.com" + "/UserName".
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";
try {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("http://instagram.com/_u/" + "username"));
intent.setPackage("com.instagram.android");
startActivity(intent);
}
catch (android.content.ActivityNotFoundException anfe)
{
startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse("https://www.instagram.com/" + username)));
}
Unfortunately, at this time you cannot open the Instagram app to go directly to a user profile. You can however open a certain photo in the Instagram app.
The following code that I have provided will open a certain photo inside of the Instagram app. If no Instagram app is installed, it will open a user profile inside of the browser.
public void openInstagram (View view) {
Intent intent = null;
String pictureId = "p/0vtNxgqHx9";
String pageName = "d4v3_r34d";
try {intent = getPackageManager().getLaunchIntentForPackage("com.instagram.android");
intent.setComponent(new ComponentName("com.instagram.android", "com.instagram.android.activity.UrlHandlerActivity"));
intent.setData(Uri.parse("http://instagram.com/" + pictureId));
} catch (Exception e) {
intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://instagram.com/" + pageName));
}
this.startActivity(intent);
I made it very easy for this code to be edited for your own purposes. Set the "String pictureId" to the id of the picture that you want to display and set the "String pageName" to the user name of your Instagram account.
The user name part is obvious but if you need help to get your picture id look at this picture.
Check the code below:
Intent instaintent = getPackageManager().getLaunchIntentForPackage("com.instagram.android");
instaintent.setData(Uri.parse("https://www.instagram.com/insta_save_new/"));
startActivity(instaintent);
Related
I'm trying to open a specific profile page from my android app, in the native facebook app. I've seen many answers about this topic, but none of them worked for me currently (maybe because some new versions)
Right now, I'm trying to open it like that:
public static Intent getFacebookIntent(PackageManager pm, String url ,String fbID) {
Intent intent;
try {
int versionCode = pm.getPackageInfo("com.facebook.katana", 0).versionCode;
boolean activated = pm.getApplicationInfo("com.facebook.katana", 0).enabled;
if(activated){
if ((versionCode >= 3002850)) {
intent = new Intent(Intent.ACTION_VIEW, Uri.parse("fb://facewebmodal/f?href=" + url));
return intent;
} else {
intent = new Intent(Intent.ACTION_VIEW, Uri.parse("fb://page/" + fbID));
return intent;
}
}else{
intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
return intent;
}
} catch (PackageManager.NameNotFoundException e) {
intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
return intent;
}
}
where fbID its the user id, and url is the "link" from user graph request.
I've tried to change the url, to a specific url like
"https://www.facebook.com/some_user_name" but not luck.
the result of that code, is that the facebook app opens and crashes.
I do able to open it with webpage link.
Thanks
I am trying to open certain Facebook profile page in my android app with specific user ID.
My code opens facebook app if it is installed otherwise open webbrowser.
It works fine except when facebook app is installed and it is closed.
In that situation it just opens newsfeed page instead of the profile page. When the facebook app is open at background, it successfully redirect to desired profile page. How can I solve this ? Also is there an official facebook document which describes about the way to access facebook app URI ?
try{
this.getPackageManager()
.getPackageInfo("com.facebook.katana", 0); //Checks if FB is even installed.
final String facebookScheme = String.format("fb://profile/%s", user2FbID);
final Intent facebookIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(facebookScheme));
facebookIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_HISTORY
| Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
startActivity(facebookIntent);
}catch (Exception e) {
String facebookScheme = "https://m.facebook.com/" + user2FbID;
Intent facebookIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(facebookScheme));
startActivity(facebookIntent);
}
Try this, Works for me
try
{
Intent followIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("fb://profile/<your profile_id>"));
startActivity(followIntent);
final Handler handler = new Handler();
handler.postDelayed(new Runnable()
{
#Override
public void run() {
Intent followIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("fb://profile/<your profile_id>"));
startActivity(followIntent);
}
}, 1000 * 2);
}
catch (Exception e)
{
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.facebook.com/<user_name>")));
String errorMessage = (e.getMessage()==null)?"Message is empty":e.getMessage();
Log.e("Unlock_ScreenActivity:FacebookAppNotFound" ,errorMessage);
}
This was happening with me too. Updated the Facebook app and it's solved now, seems it was something to do in with Facebook. It's working properly now.
Here's the code I'm using:
public static Intent getOpenFacebookIntent(Context context) {
try{
// open in Facebook app
context.getPackageManager().getPackageInfo("com.facebook.katana", 0);
return new Intent(Intent.ACTION_VIEW, Uri.parse("fb://page/<profile_id>"));
} catch (Exception e) {
// open in browser
return new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.facebook.com/<profile_id>"));
}
}
Developing an application, In which I have many user's account_id(skype id), Now what I want is to open chat screen of Skype (already installed in device) when I click particular User's skype_id from my application.
I did search on web but got no success
Got the link how to start call on Skype but for chat?
1) Link 1
2) Link 2
You can use the Skype URI Scheme for this (Skype:echo123?chat).
You can find out more information about the URI Scheme here : https://dev.skype.com/skype-uri
Thanks
Allen Smith
Skype Developer Support Manager
Here is the code to open Skype chat conversation:
private void openSkype(Context context) {
// Make sure the Skype for Android client is installed
if (!isSkypeClientInstalled(context)) {
goToMarket(context);
return;
}
final String mySkypeUri = "skype:echo123?chat";
// Create the Intent from our Skype URI.
Uri skypeUri = Uri.parse(mySkypeUri);
Intent myIntent = new Intent(Intent.ACTION_VIEW, skypeUri);
// Restrict the Intent to being handled by the Skype for Android client only.
myIntent.setComponent(new ComponentName("com.skype.raider", "com.skype.raider.Main"));
myIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
try {
context.startActivity(myIntent);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Determine whether the Skype for Android client is installed on this device.
*/
public boolean isSkypeClientInstalled(Context myContext) {
PackageManager myPackageMgr = myContext.getPackageManager();
try {
myPackageMgr.getPackageInfo("com.skype.raider", PackageManager.GET_ACTIVITIES);
} catch (PackageManager.NameNotFoundException e) {
return (false);
}
return (true);
}
/**
* Install the Skype client through the market: URI scheme.
*/
public void goToMarket(Context myContext) {
Uri marketUri = Uri.parse("market://details?id=com.skype.raider");
Intent myIntent = new Intent(Intent.ACTION_VIEW, marketUri);
myIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
myContext.startActivity(myIntent);
}
I was looking for some way to launch Twitter app and open a specified page from my application, without webview.
I found the solution for Facebook here:
Opening facebook app on specified profile page
I need something similar.
[EDIT]
I've just found a solution:
try {
Intent intent = new Intent(Intent.ACTION_VIEW,
Uri.parse("twitter://user?screen_name=[user_name]"));
startActivity(intent);
} catch (ActivityNotFoundException e) {
startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse("https://twitter.com/#!/[user_name]")));
}
Based on fg.radigales answer, this is what I used to launch the app if possible, but fall back to the browser otherwise:
Intent intent = null;
try {
// get the Twitter app if possible
this.getPackageManager().getPackageInfo("com.twitter.android", 0);
intent = new Intent(Intent.ACTION_VIEW, Uri.parse("twitter://user?user_id=USERID"));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
} catch (Exception e) {
// no Twitter app, revert to browser
intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://twitter.com/PROFILENAME"));
}
this.startActivity(intent);
UPDATE
Added intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); to fix an issue where twitter was opening inside my app instead of as a new activity.
This worked for me: twitter://user?user_id=id_num
Open page on Twitter app from other app using Android in 2 Steps:
1.Just paste the below code (on button click or anywhere you need)
Intent intent = null;
try{
// Get Twitter app
this.getPackageManager().getPackageInfo("com.twitter.android", 0);
intent = new Intent(Intent.ACTION_VIEW, Uri.parse("twitter://user?user_id=USER_ID"));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
} catch () {
// If no Twitter app found, open on browser
intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://twitter.com/USERNAME"));
}
2.intent = new Intent(Intent.ACTION_VIEW, Uri.parse("twitter://user?user_id=USER_ID"));
To get USER_ID just write username https://tweeterid.com/ and get Twitter User ID in there
Reference: https://solutionspirit.com/open-page-twitter-application-android/
My answer builds on top of the widely-accepted answers from fg.radigales and Harry.
If the user has Twitter installed but disabled (for example by using App Quarantine), this method will not work. The intent for the Twitter app will be selected but it will not be able to process it as it is disabled.
Instead of:
getPackageManager().getPackageInfo("com.twitter.android", 0);
intent = new Intent(Intent.ACTION_VIEW, Uri.parse("twitter://user?user_id=2343965036"));
You can use the following to decide what to do:
PackageInfo info = getPackageManager().getPackageInfo("com.twitter.android", 0);
if(info.applicationInfo.enabled)
intent = new Intent(Intent.ACTION_VIEW, Uri.parse("twitter://user?user_id=2343965036"));
else
intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://twitter.com/wrkoutapp"));
Just try this code snippet. It will help you.
//Checking If the app is installed, according to the package name
Intent intent = new Intent();
intent.setType("text/plain");
intent.setAction(Intent.ACTION_SEND);
final PackageManager packageManager = getPackageManager();
List<ResolveInfo> list = packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
for (ResolveInfo resolveInfo : list)
{
String packageName = resolveInfo.activityInfo.packageName;
//In case that the app is installed, lunch it.
if (packageName != null && packageName.equals("com.twitter.android"))
{
try
{
String formattedTwitterAddress = "twitter://user/" ;
Intent browseTwitter = new Intent(Intent.ACTION_VIEW, Uri.parse(formattedTwitterAddress));
long twitterId = <Here is the place for the twitter id>
browseTwitter.putExtra("user_id", twitterId);
startActivity(browseTwitter);
return;
}
catch (Exception e)
{
}
}
}
//If it gets here it means that the twitter app is not installed. Therefor, lunch the browser.
try
{
String twitterName = <Put the twitter name here>
String formattedTwitterAddress = "http://twitter.com/" + twitterName;
Intent browseTwitter = new Intent(Intent.ACTION_VIEW, Uri.parse(formattedTwitterAddress));
startActivity(browseTwitter);
}
catch (Exception e)
{
}
For me this did the trick it opens Twitter app if you have it or goes to web browser:
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://twitter.com/"+"USERID"));
startActivity(intent);
try {
Intent intent = new Intent(Intent.ACTION_VIEW,
Uri.parse("twitter://user?screen_name=[user_name]"));
startActivity(intent);
} catch (Exception e) {
startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse("https://twitter.com/#!/[user_name]")));
}
This answer was posted as an edit to the question Open page in Twitter app from other app - Android by the OP jbc25 under CC BY-SA 3.0.
How can I start an intent to open a Facebook application on a phone and navigate to the prefered page in Facebook?
I tried:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setClassName("com.facebook.katana", "com.facebook.katana.ProfileTabHostActivity");
intent.putExtra("extra_user_id", "123456789l");
this.startActivity(intent);
Well, whatever I write to "1234567891", it is always navigating to my page. Always to me and not else.
How could I do this?
Here is the best and simple way to do it.
Just follow the code
public final void Facebook() {
final String urlFb = "fb://page/"+yourpageid;
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(urlFb));
// If Facebook application is installed, use that else launch a browser
final PackageManager packageManager = getPackageManager();
List<ResolveInfo> list =
packageManager.queryIntentActivities(intent,
PackageManager.MATCH_DEFAULT_ONLY);
if (list.size() == 0) {
final String urlBrowser = "https://www.facebook.com/pages/"+pageid;
intent.setData(Uri.parse(urlBrowser));
}
startActivity(intent);
}
I had the exactly same problem, sent the user id but for some reason, my profile always opened instead of the friend's profile.
The problem is that if you pass the String of the Long object that represents the Facebook UID, or even a long primitive type, the intent won't be able to read it later. You need to pass a real Long.
So the complete code is:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setClassName("com.facebook.katana", "com.facebook.katana.ProfileTabHostActivity");
Long uid = new Long("123456789");
intent.putExtra("extra_user_id", uid);
startActivity(intent);
Ok enjoy and hope this helps :-)
Maxim
try this code :
String facebookUrl = "https://www.facebook.com/<id_here>";
try {
int versionCode = getPackageManager().getPackageInfo("com.facebook.katana", 0).versionCode;
if (versionCode >= 3002850) {
Uri uri = Uri.parse("fb://facewebmodal/f?href=" + facebookUrl);
startActivity(new Intent(Intent.ACTION_VIEW, uri));
} else {
Uri uri = Uri.parse("fb://page/<id_here>");
startActivity(new Intent(Intent.ACTION_VIEW, uri));
}
} catch (PackageManager.NameNotFoundException e) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(facebookUrl)));
}
This solution won't work any more. The new version of the facebook app doesn't support anymore those kind of intents. See here the bug report
The new solution is to use the iPhone scheme mechanism (Yes, facebook decided to support the iPhone mechanism in Android instead of the implicit intent mechanism of Android).
So in order to open the facebook app with a user profile all you need to do is:
String facebookScheme = "fb://profile/" + facebookId;
Intent facebookIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(facebookScheme));
startActivity(facebookIntent);
If you are looking for other actions you can use the following page for all available actions (/you have to test it though, since I didn't find an official publication of facebook about this)