I know is a well-known topic, but none of the solutions worked for me.
I'm using this code to launch facebook app at a specific profile page from my app:
try {
Intent fb_intent = new Intent(Intent.ACTION_VIEW, Uri.parse("fb://page/" + id_facebook));
fb_intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
startActivity(fb_intent);
} catch (Exception e) {
Intent fb_intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.facebook.com/" + id_facebook));
fb_intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
startActivity(fb_intent);
}
Facebook App opens correctly but shows an infinite loop with no data at all on the requested profile page.
Any idea why? Thank a lot in advance
I try to figure out with similar trouble..
public static Intent newFacebookIntent(PackageManager pm, String userId) {
Uri uri;
try {
pm.getPackageInfo("com.facebook.katana", 0);
uri = Uri.parse("fb://facewebmodal/f?href=" + userId);
} catch (PackageManager.NameNotFoundException e) {
uri = Uri.parse(userId);
}
return new Intent(Intent.ACTION_VIEW, uri);
}
For it's work fine
https://stackoverflow.com/a/24547478/3864698
Related
I tried to open page my Instagram page for a user who wants to follow. I tried some code to do that work:
private void followInsta() {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("https://www.instagram.com/motivationalquotes.app"));
try {
intent.setPackage("com.instagram.android");
startActivityForResult(Intent.createChooser(intent, mContext.getResources().getString(R.string.app_name)), 1000);
} catch (Exception e) {
try {
Log.e("FollowInsta1>>>", Log.getStackTraceString(e));
intent.addCategory(Intent.CATEGORY_BROWSABLE);
startActivityForResult(Intent.createChooser(intent, mContext.getResources().getString(R.string.app_name)), 1000);
} catch (Exception ex) {
Log.e("FollowInsta2>>>", Log.getStackTraceString(ex));
}
}
}
I called this from a click event but its always open dialog with a message My app name and 'No apps can perform this action'
This is only happening with the Samsung Galaxy J8 device. But it normally works on other devices. If anyone knows what to try for these types of devices then please tell me. I also tried this to solve my problem but it didn't work!
Try this snippet:
Uri uri = Uri.parse("http://instagram.com/_u/motivationalquotes.app");
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/motivationalquotes.app")));
}
This should open the app if installed or call the browser.
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 just linked some social networks to my app as a preliminary test and using the same kind of code, the results I am getting are different for Facebook, Instagram and Twitter intents.
When I click Facebook or Twitter, it opens the app automatically when it's installed and uses browser when it's not. However, that's not the case with Instagram. The complete action using dialog pops up and that's not something I want to happen.
protected void LaunchInstagram() {
String InstagramUsername = "USERNAME";
String LaunchInstagram = "http://instagram.com/_u/" + InstagramUsername;
String InstagramURL = "https://instagram.com/" + InstagramUsername;
try {
this.getPackageManager().getPackageInfo("com.instagram.android", 0);
Uri Uri = Uri.parse(LaunchInstagram);
startActivity(new Intent(Intent.ACTION_VIEW, Uri));
} catch (PackageManager.NameNotFoundException InstagramAppNotFoundOpenBrowser) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(InstagramURL)));
}
}
You are using
String InstagramURL = "https://instagram.com/" + InstagramUsername;
So every Intent you'll try to launch, will open a chooser because this is a URL.
than every App that supports URL, like browsers and such, will try to handle that.
EDIT 1:
Try it this way:
public static boolean openApp(Context context, String packageName) {
PackageManager manager = context.getPackageManager();
try {
Intent i = manager.getLaunchIntentForPackage(packageName);
if (i == null) {
return false;
//throw new PackageManager.NameNotFoundException();
}
i.addCategory(Intent.CATEGORY_LAUNCHER);
context.startActivity(i);
return true;
} catch (PackageManager.NameNotFoundException e) {
return false;
}
}
I'm not sure if that will help you to open a specific user page on the App thou.
EDIT 2:
Try it this way:
Uri uri = Uri.parse("http://instagram.com/_u/USERNAME");
Intent insta = new Intent(Intent.ACTION_VIEW, uri);
insta.setPackage("com.instagram.android");
startActivity(insta);
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>"));
}
}
I made a simple code that will download a app from Google Play.I tried
the code and tested it on real device but I got an error called "No application can perform this action."I declared android.permission.INTERNET in the manifest, but still doesn't work.
I would be glad if you can help me out.
Intent i = new Intent(android.content.Intent.ACTION_VIEW);
i.setData(Uri.parse("market://developer?*/urlofgoogleplay*/"));
chooser = Intent.createChooser(i,"Launch Market");
startActivity(chooser);
public static void linkGooglePlay(Context context) {
Uri uri = Uri.parse("market://details?id=" + context.getPackageName());
Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri);
try {
context.startActivity(goToMarket);
} catch (ActivityNotFoundException e) {
context.startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse("http://play.google.com/store/apps/details?id=" + context.getPackageName())));
}
}
This is the right syntax:
i.setData(Uri.parse("market://details?id=" + app_package));
Here's the documentation