[FIXED] How can I handle correctly facebook embed element on webview android app?

Issue

I created native android web based application using web view element.
the app relies on my website and In my website there is facebook embed element(That added using Elementor Pro [WORDPRESS]) – link to website

The Facebook Element:

Facebook element

I have few questions:

  1. is it possible to handle the facebook login and like to my page in the facebook app if exists?
  2. How can I handle it in the right way – when user clicks on this element the web view opens facebook login page in desktop view mode and I want it in mobile view mode.

take a look:

loginstration

  1. After the login The webview shows link to back to my web site and after going back to the website if the user presses back button he will see the link again, how to fix it?

back to my website

  1. when the user presses like button of any post the web view showing empty screen with the number "1":

webview after like button

I need your help with handling this facebook element.
Thank you all in advance!

Solution

After 2 day of research I found possible solution.
This solution will not allow the user to give me a like to my Facebook page it just allow to see my Facebook page in Facebook app if installed:

    String pageUrl = String.format("fb://facewebmodal/f?href=%s", Constants.OUKITEL_FACEBOOK_PAGE_URL);//replace OUKITEL_FACEBOOK_URL with your page url

    Intent operation = new Intent(Intent.ACTION_VIEW, Uri.parse(pageUrl));
    try {

        if(isPackageInstalled(ctx, packageName)) {
            operation.setPackage(packageName);
        }
        ctx.startActivity(operation);
    }catch (Exception e) {
        Toast.maketext(MainActivity.this, "Facebook app is not installed")
    }

And ‘isPackageInstalled’ is a private method:

public static boolean isPackageInstalled(Context ctx, String packageName) {
    PackageManager pm = ctx.getPackageManager();
    try {
        return pm.getApplicationInfo(packageName, 0).enabled;
    } catch (PackageManager.NameNotFoundException e) {
        return false;
    }
}

Answered By – Barel elbaz

Answer Checked By – Dawn Plyler (Easybugfix Volunteer)

Leave a Reply

(*) Required, Your email will not be published