Open Facebook native app from your android app - android

My question is directly connected with this one Open Facebook page from Android app? Which answer (for the version at the moment) is not the marked one but this one
public static Intent newFacebookIntent(PackageManager pm, String url) {
Uri uri;
try {
pm.getPackageInfo("com.facebook.katana", 0);
// https://stackoverflow.com/a/24547437/1048340
uri = Uri.parse("fb://facewebmodal/f?href=" + url);
} catch (PackageManager.NameNotFoundException e) {
uri = Uri.parse(url);
}
return new Intent(Intent.ACTION_VIEW, uri);
}
Which is confirmed working last on 7th of February 2015.
My question is should you use the whole url (like www.facebook.com/mypage) or just add the url of the page so it'll be fb://facewebmodal/f?href=mypage. I tried both and it just opens the fb app without an actual page. It shows blank fb page on both tries.
Can someone give me an example with url for some public page that works?

You can try to write mypage as https://www.facebook.com/ID. The whole uri should then be
fb://facewebmodal/f?href=https://www.facebook.com/ID
and change ID to the page you want to visit.

That functionality is not documented or supported, so you may get unknown result. You may want to try passing the Page ID or Profile ID instead of names. You can get the ID by calling https://graph.facebook.com/<name> and parse the result.

I had the same issue. I searched for a while and tried all the answers on here Open facebook page from android app (in facebook version > v11) and there Open Facebook page from Android app?, finally I figured out what the real problem is. There is nothing wrong in the code, however the weird behavior is about facebook app itself. If the facebook app is on the background, it just switches back to the foreground without navigating to the requested page. You just swipe it out from the background (kill instances) and try your code again.
Considering most of the users leave facebook app on the background, this is some kind of an issue needs to be fixed. Although I think it is about the facebook app itself, somehow it can be related with the device. I'm using Nexus 6 with v 6.0.1 and had no chance to test it on another android versioned device.

i using this for my apps its working just fine, kotlin
try {
val intent = Intent(Intent.ACTION_VIEW, Uri.parse("fb://page/100674618166286"));
startActivity(intent);
} catch(e: Exception) {
startActivity( Intent(Intent.ACTION_VIEW, Uri.parse("http://www.facebook.com/iqtousd")));
}

Remember have a similar issue.
Try the mobile url :
instead of
String facebookUrl = "https://facebook.com/...";
use
String facebookUrl = "https://m.facebook.com/...";

Related

Android testing - change system value for testing logical branch

I've got a method that tries to start a browser with a specific URL, or if the device does not have a browser installed, instead starts an Activity with a WebView and loads the same URL. Basically this:
try {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
getActivity().startActivity(intent);
} catch (ActivityNotFoundException e) {
Intent intent = new Intent(getActivity(), MyWebView.class);
intent.putExtra(EXTRA_URL, url);
getActivity().startActivity(intent);
}
}
How can I test both branches? Is it possible to unregister the Browser activity from the device, temporarily and programmatically?
I had considered a Shadow Activity that just throws an ActivityNotFoundException when that particular Intent was passed to it (i'd check the data URI), but AFAIK there's no way to turn that Shadow on for one test and off for the other.
TYIA
This is really over engineering. The odds that the user doesn't have a web browser on the device is 0. It isn't worth worrying about.
If you're worried about the url being invalid and unparsable, its unlikely this would fix that problem, as it would be unparsable in your web view activity as well. If you really want to be paranoid I'd catch it and toast an error.
As for testing it- refactor to make it testable. Write this as a function that takes a URL as a parameter. For the bad version, use a URL like thisisnotavalidscheme://example.com. That will fail as nobody is going to be registered for that scheme.

firebase dynamic link preview link not working with facebook messenger

Created firebase dynamic short link will not preview correctly in facebook messenger.
It puts up the message and link as expected and shows a preview image with url.
The url included in the message is working but not the url if I click on the preview.
The url should be : https://q3zbm.app.goo.gl/8f7b
but the preview link becomes https://q3zbm.app.goo.gl/s?socialDescription=Welcome&socialImageUrl=http://andreasandersson.nu/images/awesome-photo.jpg&socialTitle=Gooo
I was able to reproduce this in a very small program
private void generate() {
DynamicLink.SocialMetaTagParameters.Builder params = new DynamicLink.SocialMetaTagParameters.Builder();
params.setImageUrl(Uri.parse("http://andreasandersson.nu/images/awesome-photo.jpg"));
params.setDescription("Welcome");
params.setTitle("Gooo");
FirebaseDynamicLinks.getInstance()
.createDynamicLink()
.setLink(Uri.parse("http://andreasandersson.nu"))
.setDynamicLinkDomain("q3zbm.app.goo.gl")
.setIosParameters(new DynamicLink.IosParameters.Builder("ios.app.example").build())
.setAndroidParameters(new DynamicLink.AndroidParameters.Builder().build())
//.setSocialMetaTagParameters(params.build())
.buildShortDynamicLink(SHORT)
.addOnCompleteListener(new OnCompleteListener<ShortDynamicLink>() {
#Override
public void onComplete(#NonNull Task<ShortDynamicLink> task) {
if (task.isSuccessful()) {
Uri shortLink = task.getResult().getShortLink();
Uri flowchartLink = task.getResult().getPreviewLink();
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shareIntent.putExtra(Intent.EXTRA_TEXT, "check this:" + shortLink.toString());
shareIntent.setType("text/plain");
startActivity(Intent.createChooser(shareIntent, "share"));
}
}
});
}
I know that the app values are not correct but inputting correct ones gives no difference in the result.
Is this an error on the firebase dynamic link or is the problem with facebook messenger?
When doing the exact same thing from ios it is working as intended which should mean that this is a android related issue with the sharer?
Update: Thanks for contacting FIrebase support. This is an issue with Facebook that we already raised to them. As of now, we are yet to hear any updates from them, but once we do, we'll let you know.
I think that Facebook will not allow this because it would be in violation of their Fake news issue. The ability to change the image used when sharing links was removed and the Firebase meta info would allow you to circumvent this.
Update
After playing around with URL's it turns out I had a trailing "/" before "?" which was preventing the link working with Facebook. Using firebase links we can now set all meta info and provide custom thumbnails again.
I filed the similar question to Firebase support before. According to their support, it seems that it's on Facebook's side and they've filed a bug on Facebook. They also provided the bug tracker (https://business.facebook.com/direct-support/question/124595778189376/?force_full_site=0&business_id=191383518008569) but it appears I don't have necessary access to view the tracker, so I think this might also apply to you.

using deep linking in android with adds

How to open specific page of another app on clicking add in app in android ? I am creating an android app in which add are showing .when clicking on that add it opens the play store. But i want to open specific page of that app using deeplinking. e.g am getting snapdeal offers add in my application when i click on that add it open the specific page of snapdeal.How to do that ?
Add the package name of the app you want to open in playstore:
String appPackageName = "package_xy"; // eg. com.twitter.android
try {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName)));
}catch (android.content.ActivityNotFoundException e) {
//if playstore app not installed
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id=" + appPackageName)));
}
So you probably would need your advertisement to send the package name of their app with it. Or just an url to open (maybe send the playstore browser link in the catch above if its an app, so you could detect the play.google.com part and replace accordingly or just open the plain website if its not a playstore url).
You asked what happens if the app is already installed: Still the same. You should check for it first:
Intent i;
PackageManager manager = getPackageManager();
String appPackageName = "package_xy";
try {
i = manager.getLaunchIntentForPackage(appPackageName);
if (i == null)
throw new PackageManager.NameNotFoundException();
i.addCategory(Intent.CATEGORY_LAUNCHER);
startActivity(i);
} catch (PackageManager.NameNotFoundException e)
{
//open playstore instead
}
So this is only one of many ways. If the app is not found on the device, the try will fail and catch is executed. If it is found it will be opened.
In the case of twitter I even could open it with a deeplink like this:
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("twitter://status?status_id="+id));
For some things like PDF there are ways to open the applicationpicker, but I don't think thats what you need in this case.
You should be fine if you use the above code. Just put the first snippet in the catch of the second one and you should be fine.

Share via Google+..dialog complete action with shown

hi everybody i've a little problem..i'm trying to share a text using google plus app, but the lastest version give me a problem.
when i call with an intent "com.google.android.apps.plus", android display me this dialog
so if i choose the first one, text will be shared correctly, but the second one do nothing.
if the app is not intalled i redirect the user to the market, at g+ download page (this work fine)
if (v == plus) {
social(2);
targetedShareIntent.putExtra(
android.content.Intent.EXTRA_TEXT, user);
targetedShareIntent
.setPackage("com.google.android.apps.plus");
startActivity(targetedShareIntent);
}
"v" is a button and social check if app is installed
any sugestion?
both options open google+ application?
I suppose show two options because google+ app have two activities with category.LAUNCHER.... the app and the chat app
PSDT: sorry for my bad english!
I was able to get the G+ dialog to launch with the following code (after querying the package manager to make sure the app was actually installed and passing in the currentContext as a parameter):
Intent appIntent = new Intent(Intent.ACTION_SEND);
String shareText = "Share text goes here";
appIntent.setType("text/plain");
appIntent.putExtra(Intent.EXTRA_TEXT, shareText);
//Filters so only the G+ app will launch
appIntent.setPackage("com.google.android.apps.plus");
try {
currentContext.startActivity(appIntent);
} catch (android.content.ActivityNotFoundException e) {
Log.d(e.getMessage());
}
Drove me bananas figuring this out, so I figured I'd try to save someone else the hassle.

Android: starting a default application or one which may be different on different devices

I would like to start a default application: browser, contact-book, phone, email, music app, etc. I have found many q/a, like browser opening a specific URL or blank, and here the answer is even "No not possible". But I would like to just open/launch it without telling it to go to a specific URL or sending a mail to someone, etc.
However, I also saw some Home applications where this seems to be working (at least for some apps). On my colleague's device there is for example a different contact-book (no google) which is detected and opened correctly.
I have seen in the Android documentation some intent categories that point to these problems, but these are only >= API.11. So I can't use/test them on my device.
Question: Is it not somehow possible to launch a default application (having the app chooser is of course ok) without providing extra data? If no, what do you think are these Home apps doing (perhaps workarounds are somehow possible).
PS: for the phone app I think, I have a workaround using Intent.ACTION_DIAL without any other information which will open simply the dialer.
UPDATE: I modified the title. Some applications like the address book may not be the same on different devices. So in this case I would like to start the address-book app, whichever this is.
This answer is not a 100% answer, but some workarounds on some typical applications.
Still open are: music player, address book
Browser: I get a list of applications that handle "http"-data intents, and then I look if one is available in the list of preferred applications.
Intent appFilter = new Intent(Intent.ACTION_VIEW);
appFilter.setData(Uri.parse("http://www.google.com"));
List<ResolveInfo> browserInfoList = pm.queryIntentActivities(appFilter, 0);
List<IntentFilter> outFilters = new ArrayList<IntentFilter>();
List<ComponentName> outActivities = new ArrayList<ComponentName>();
pm.getPreferredActivities(outFilters, outActivities, null);
if(outActivities.size() > 0) {
for(ComponentName cn : outActivities) {
String cnClass = cn.getClassName();
String cnPkg = cn.getPackageName();
for (ResolveInfo info : browserInfoList) {
if(info.activityInfo.name.equals(cnClass) &&
info.activityInfo.packageName.equals(cnPkg)) {
return cn;
}
}
}
}
In case no default is found, I open a browser chooser dialog, see here.
Phone: as described in the question:
Intent intent = new Intent(Intent.ACTION_DIAL);
startActivity(intent);
You can start apps by the function "startActivity" if you know about the canonical app name
like "android.com.browser". Do this simple by searching for AndroidManifest.xml in the app
source code (look at Codeaurora.com or at github/Cyanogenmod) and grab the app name you want.
After you know about the App name ("Activity") implement the code as follows:
Intent intent = new Intent();
intent.setClassName(this, "com.android.browser");
intent.setCategory(Intent.ACTION_MAIN);
startActivity(intent);
THIS is only a example, sometimes you have to put intent extras or data values, this information can be found in the app's AndroidManifest.xml too.

Categories

Resources