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?
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.
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.
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.
Syntax: Intent i = new Intent(getApplicationContext(), ActivityTwo. class); startActivity(i); For Example: In the below example, there are two activities (FirstActivity, and SecondActivity).
The answer was to add the default category to the second intent filter, just as @advantej suggested.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With