Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Launch Activity From URL

I am trying to have my application launch when the user browses to a certain url. I have found a few examples and they all have the same things in the manifests but it's not working for me. I have put the intent-filter under an Activity as well as a Receiver.

Here is my manifest snippet:

<intent-filter>
  <action android:name="android.intent.action.VIEW"></action>
  <category android:name="android.intent.category.DEFAULT"></category>
  <category android:name="android.intent.category.BROWSABLE"></category>
  <data android:host="www.urbandictionary.com" android:scheme="http"></data>
</intent-filter>

When under the Activity, I tried using onNewIntent and when it was under a Receiver, I tried using onReceiveIntent, both with a simple Log.i call to see if it fired or not. I am not having much luck.

like image 289
Arcane Feenix Avatar asked Mar 05 '10 17:03

Arcane Feenix


People also ask

How do I open a URL with intent?

To open a URL/website you do the following: String url = "http://www.example.com"; Intent i = new Intent(Intent. ACTION_VIEW); i.

How do I open an app from a website?

Adding Javascript to Your Website to Open Your App You merely need to add some Javascript to your website that will auto trigger your app open. The function below, triggerAppOpen, will attempt to open your app's URI scheme once you replace your_uri_scheme with the one you added in the manifest above.

How do I launch an activity using intent?

To start an activity, use the method startActivity(intent) . This method is defined on the Context object which Activity extends. The following code demonstrates how you can start another activity via an intent. # Start the activity connect to the # specified class Intent i = new Intent(this, ActivityTwo.


1 Answers

I use this in my manifest.xml file:

<activity android:name=".SomeName">
    <intent-filter>
        <category android:name="android.intent.category.ALTERNATIVE" />
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data android:host="google.com" android:scheme="http" />  
    </intent-filter>
</activity>

This will start activity SomeName. I don't use www in the android:host part maybe that will make a difference.

When the activity starts you can get the data that's behind the .com using (for example):

Uri data = getIntent().getData();
if(data != null && data.getPathSegments().size() >= 2){
    List<String> params = data.getPathSegments();
    String somestuff = params.get(0);
}

Edit: If you wan't to be able to check the host from within the activity, use this method:

data.getHost();
like image 53
Rolf ツ Avatar answered Oct 05 '22 14:10

Rolf ツ