How to add a Xamarin custom browser to the andriod default browser list?

Yongqing Huang 241 Reputation points
2022-01-10T11:27:09.427+00:00

I used Xamarin.Android Web View to develop a custom browser,
How to add my Xamarin custom browser app to the andriod default browser list?
So that the users can change the default browser to mijn custom browser.
My custom browser will be started when a url is clicked.

Thanks in advance!

Developer technologies | .NET | Xamarin
0 comments No comments
{count} votes

Accepted answer
  1. Anonymous
    2022-01-11T09:38:52.067+00:00

    Hello,​

    Welcome to our Microsoft Q&A platform!

    You can achieve it by adding IntentFilter above your Activity like following code. Then your application will appear at android system default browser list.

    The key is include the <category android:name="android.intent.category.BROWSABLE" /> in your target activity's intent-filter as developer documentation said:

    If the user is viewing a web page or an e-mail and clicks on a link in the text, the Intent generated execute that link will require the BROWSABLE category, so that only activities supporting this category will be considered as possible actions.

       [Activity(Label = "@string/app_name", Theme = "@style/AppTheme", MainLauncher = true)]  
           [IntentFilter(new[] { Android.Content.Intent.ActionView },   
               Categories = new[] { Android.Content.Intent.CategoryDefault,Android.Content.Intent.CategoryLauncher, Android.Content.Intent.CategoryBrowsable},   
               DataSchemes = new[] { "http", "https" }  
               
               )]  
           public class MainActivity : AppCompatActivity  
           {  
    

    Best Regards,

    Leon Lu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


2 additional answers

Sort by: Most helpful
  1. Yongqing Huang 241 Reputation points
    2022-01-13T16:41:38.68+00:00

    Hi Leon,

    we would like to have respond to an URL without http:// or https://, too.
    For example: learn.microsoft.com

    I tried twice by changing code to DataSchemes = new[] { "http", "https", "" } and DataSchemes = new[] { "http", "https", "*" }

    It worked by SMS (Messages) , but not by email (Outlook)

    What is your idea about this? (how to specify DataSchemes)

    respond to learn.microsoft.com when click it in email (Outlook):
    164749-afbeelding.png


  2. Yongqing Huang 241 Reputation points
    2022-01-14T08:37:37.58+00:00
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.