Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I create browsable intent in the android manifest?

I have an Android app that should open links sent via email. I only want to open links to a certain website, though. I know that opening youTube links provides the user with a dialog asking whether to open it in the browser or in the youTube app, so this is what I am going for. In my android manifest file, I have the following intent filters:

    <activity android:name=".MyApp"
              android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.BROWSABLE"/>
            <data android:scheme="http"
                  android:host="mySite.com" />

        </intent-filter>
    </activity>

Then, to handle the intent, I have a line in onCreate:

if (getIntent().getCategories().contains("android.intent.category.BROWSABLE")){...}

The problem is that links such as http://mySite.com#12345 are not opening this way. What am I doing wrong?

like image 795
Phil Avatar asked May 31 '11 13:05

Phil


People also ask

What is browsable activity in android?

Include the BROWSABLE category. It is required in order for the intent filter to be accessible from a web browser. Without it, clicking a link in a browser cannot resolve to your app. Also include the DEFAULT category. This allows your app to respond to implicit intents.

How do I set extras Intent?

Using putExtra() We can start adding data into the Intent object, we use the method defined in the Intent class putExtra() or putExtras() to store certain data as a key value pair or Bundle data object. These key-value pairs are known as Extras in the sense we are talking about Intents.

What is Intent filter in android manifest?

An intent filter is an expression in an app's manifest file that specifies the type of intents that the component would like to receive. For instance, by declaring an intent filter for an activity, you make it possible for other apps to directly start your activity with a certain kind of intent.

What is the syntax of Intent in android?

Syntax: Intent i = new Intent(getApplicationContext(), ActivityTwo. class); startActivity(i); For Example: In the below example, there are two activities (FirstActivity, and SecondActivity).


1 Answers

The answer was to add the default category to the second intent filter, just as @advantej suggested.

like image 144
Phil Avatar answered Oct 18 '22 06:10

Phil