Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8505783
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T02:25:04+00:00 2026-06-11T02:25:04+00:00

The Requirements: I have a share button in my app. I have a requirement

  • 0

The Requirements:

I have a “share” button in my app. I have a requirement to share via Facebook. I need to have the option whether or not the native Facebook app is installed. Our decision is to send the user to facebook.com to share if the app is not installed.

The Current State:

I can detect when the native app is not installed (via the package name), and add additional intents to the chooser.

The Problem:

The item the user has to select to share via “Facebook’s Website” says, “Browser” and has the Android Browser icon.
The LabeledIntent item does not appear and I get a “No activity found for Intent { act=android.intent.action.VIEW dat=…}

The Code (simplified…):

Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_SUBJECT, "check this out");
intent.putExtra(Intent.EXTRA_TEXT, urlToShare);
boolean facebookInstalled = false;

Intent chooser = Intent.createChooser(intent, "Share this link!");
if (!facebookInstalled)
{
    Intent urlIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.facebook.com/sharer/sharer.php?u=" + Uri.encode(urlToShare)));
    Intent niceUrlIntent = new LabeledIntent(urlIntent, context.getApplicationContext().getPackageName(), "Facebook's Website", R.drawable.icon);

    // Ideally I would only add niceUrlIntent in the end, but that doesn't add anything to the chooser as-is
    chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[urlIntent, niceUrlIntent]);
}
context.startActivity(chooser);

The Solution

The solution as @CommonsWare pointed out, is to use the LabeledIntent to wrap an intent that goes to a new Activity I create, that simply sends a ACTION_VIEW intent to the appropriate Uri.

Intent myActivity = new Intent(context, ViewUriActivity.class);
myActivity.putExtra(ViewUriActivity.EXTRA_URI, "http://...");
Intent niceUrlIntent = new LabeledIntent(myActivity, context.getApplicationContext().getPackageName(), "Facebook's Website", R.drawable.icon);
chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[]{niceUrlIntent});

The ViewUriActivity looks like this:

public final class ViewUriActivity extends Activity
{
    public static final String EXTRA_URI = ViewUriActivity.class.getSimpleName() + "EXTRA_URI";

    protected void onCreate(final Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);

        Intent urlIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(getIntent().getExtras().getString(EXTRA_URI)));
        startActivity(urlIntent);
        finish();
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T02:25:06+00:00Added an answer on June 11, 2026 at 2:25 am

    Though undocumented, looks like LabeledIntents only work on resolved Intents. So unless the intent already has a specific activity and package defined you will not be able to use it.

    This is not surprising since there may be many Activities that might get resolved for one LabeledIntent and your chooserActivity will show all icons and names as same.

    So in your case you will have to resolve the acctivity first and then use LabeledIntent. But this might result in user not able to choose browser of their choice.
    Use below function to get LabeledIntent from you intent.

    Intent urlIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.facebook.com/sharer/sharer.php?u=" + Uri.encode(urlToShare)));
    Intent niceUrlIntent = getLabelintent(urlIntent, "Facebook's Website", R.drawable.icon);
    

    And getLabelIntent

    public LabeledIntent getLabelintent(Intent in, String name, int drawable) {
        PackageManager pm = getPackageManager();
        ComponentName launchname = in.resolveActivity(pm);
        if (launchname != null) {
            Intent resolved = new Intent();
            resolved.setComponent(launchname);
            resolved.setData(in.getData());
            LabeledIntent niceUrlIntent = new LabeledIntent(resolved,
                    getPackageName(), name, drawable);
    
            return niceUrlIntent;
        }
        return null;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have developed my news app and now i have to add share(facebook/twitter)option to
I have a business requirement to add a Share on Facebook button to a
Here I have 2 requirements: Need a batch file to start a process on
Requirements : I have a table of several thousand questions. Users can view these
I have the following requirements I have relational content stored in a SQL Server
I have requirements to establish a CMS system for enterprise and it has to
Here are my requirements: I have a DIV which should display an image (JPEG).
Can someone recommend a hosted solution that answers the following requirements (I have seen
I have received requirements that ask to normalize text box content when the user
I have some credential requirements for my modules in security.yml. How can i run

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.