Ashraf Alshahawy
Ashraf Alshahawy

Reputation: 1189

How to implement Facebook App Link in Android with example

Is it possible to post on Facebook from my Android application and this post function as App Link? Where if someone using Facebook application tapped on this post it will be directed to G.P. to install my app, and if it's installed it will open my app with enough data to view this post in my app activity?

So far I couldn't find an example that shows how to create an App Link object, and how to include data in this object to be retrieved later from intent -> extras, and I'm totally confused how to implement it in Android.

For example, from my application I want to share an http://youtube.com/xxxxx link in a post on Facebook, how to create the App Link using Facebook App Link host feature?

Edit 1:

I need to understand something about app linking, do I create an app link for each post will be posted from my application, or app link is created once to represent my application?

Edit 2:

How to get my app name to be in Blue as Instagram and clicking on it opens my application or go to my Google Play to install if not installed

How to get my app name to be in Blue as Instagram and clicking on it opens my application or go to my

Edit 3:

This is the code I use to share, but I don't get my application name a "clickable blue link" as Instagram as in the picture:

    ShareDialog shareDialog = new ShareDialog(mMainActivity);

    if (ShareDialog.canShow(ShareLinkContent.class))
    {
        ShareLinkContent linkContent;
        if(aURL == null)
        {
            linkContent = new ShareLinkContent.Builder().build();
        }
        else
        {
            linkContent = new ShareLinkContent.Builder()
                    .setContentUrl(Uri.parse(aURL))
                    .build();
        }

        shareDialog.show(linkContent);
    }

Shall I make a specific changes in my application settings page on Facebook dashboard?

Upvotes: 3

Views: 5561

Answers (3)

APP Bird
APP Bird

Reputation: 1381

You should use open graph actions for that. first you should create a object . then add an action type. then needs to create a story. & you have to submit for review process your facebook app. Normally share code looks like this. read the docs https://developers.facebook.com/docs/sharing/opengraph/android. & you need to use app links - https://developers.facebook.com/docs/applinks/android

// Create an object
ShareOpenGraphObject object = new ShareOpenGraphObject.Builder()
    .putString("og:type", "books.book")
    .putString("og:title", "A Game of Thrones")
    .putString("og:description", "In the frozen wastes to the north of Winterfell, sinister and supernatural forces are mustering.")
    .putString("books:isbn", "0-553-57340-3")
    .build();

// Create an action
ShareOpenGraphAction action = new ShareOpenGraphAction.Builder()
    .setActionType("books.reads")
    .putObject("book", object)
    .build();

// Create the content
ShareOpenGraphContent content = new ShareOpenGraphContent.Builder()
    .setPreviewPropertyName("book")
    .setAction(action)
    .build();

ShareDialog.show(activityOrFragment, content);

Upvotes: 2

Ankit Garg
Ankit Garg

Reputation: 719

I tried the same thing. It turns out that your app should be present on app center (facebook). Then only it will turn into blue link.

In my case, I tried clicking the link, but it landed on a page which said:

Misconfigured App Sorry, "My app" hasn't been approved for display in App Centre.

So I got the hint from this.

Upvotes: 0

Pdksock
Pdksock

Reputation: 1030

If I understand your question correctly, you want to post to facebook(a URL) from your app. What you can do is:

Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, your_link_here );  
startActivity(Intent.createChooser(intent, "Share via"));

This will open up a list of apps where you can share your link which includes facebook app if it is installed. Also have a look at facebook's TOS. You cannot prefill a message as it is against their policy. If you want to share some text along with your URL you will have to use facebook's SDK.

Upvotes: 0

Related Questions