Eliran
Eliran

Reputation: 207

Facebook Android App Link

I have a new app and I'm trying to implement it to "Call to Action" facebook page button, but I have no idea what I shall write in the "App link" text box.

They put an example link of: example://location/123456

But I have no idea what it's refering to or what's the App Link of my app.

Tried to find anything about it on the Internet but couldn't find any helpful solution since I have no app links in my app (no products etc)

My goal is that when the user clicks on Facebook "Use App", it will redirect him to the app or the google play store app page if it's not installed..

I'm not talking about open app in my app, im talking about open my app in my facebook page

enter image description here

enter image description here

Upvotes: 1

Views: 856

Answers (2)

Víctor Martín
Víctor Martín

Reputation: 3450

You can use the next code from the wiki:

/** Open another app.
 * @param context current Context, like Activity, App, or Service
 * @param packageName the full package name of the app to open
 * @return true if likely successful, false if unsuccessful
 */
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;
    }
}

Example usage:

openApp(this, "com.google.android.maps.mytracks");

You can read it from here

To post a message in FB, see the next post, maybe it will be useful How to open the Facebook Write Post with some pre defined text and image

Upvotes: 1

Milad Nouri
Milad Nouri

Reputation: 1597

You should use Try/Catch. if user have Facebook app, fb://page/12345 link will open in app. Else, Catch code will run.

        @Override
        public void onClick(View v) {
            try {
                startActivity(new Intent(Intent.ACTION_VIEW, Uri
                        .parse("fb://page/12345"))); //12345 is Facebook page number
            } catch (Exception e) {
                //open play link in browser
                startActivity(new Intent(Intent.ACTION_VIEW, Uri
                        .parse("http://play.google.com/etc")));
            }
        }

Upvotes: 0

Related Questions