4

This topic has been covered before, but I can't find an answer specific to what I'm asking.

Where I am: I followed hackmod's first piece of advice here: Make a link in the Android browser start up my app? and got this to work with a link in the webpage.

However, I'm having trouble understanding the second option (intent uri's). here's what I've got:

    <activity android:name="com.myapps.tests.Layout2"
        android:label="Auth Complete"
        >
        <intent-filter>
          <action android:name="android.intent.action.VIEW" />
          <category android:name="android.intent.category.DEFAULT" />
          <category android:name="android.intent.category.BROWSABLE" />
          <data android:scheme="http" android:host="mydomain.com"
                android:path="/launch" />
        </intent-filter>
    </activity>

Now, with that I can go to "mydomain.com/launch" and it launches my activity. this all works well, except that I get the chooser. what I want is for it to just launch my activity without giving options.

From the explanation in the post I referenced it looks like thats what intent uris are for,but I can't find a straightforward example. what should my link in my webpage look like in order to launch this with no chooser?

I've seen a couple of examples that look something like this:

<a href="intent:#Intent;action=com.myapp.android.MY_ACTION;end">

However, that doesn't seem to work when I try it.

My test device is a Galaxy Tab 2.

any help would be appreciated.

Community
  • 1
  • 1
Chris
  • 125
  • 1
  • 3
  • 12
  • Specifically can someone explain to me how to structure that intent:#Intent type URL, as it is the recommended method. – Chris Mar 24 '13 at 21:08

4 Answers4

8

I was also trying to launch the app in the recomended way. The following code worked for me.

Code inside the <activity> block of YourActivity in AndroidManifest.xml :

<intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
    <action android:name="your.activity.namespace.CUSTOMACTION" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />
</intent-filter>

Code in the activities onCreate() method :

Intent intent = getIntent();
if(intent != null && intent.getAction() == "your.activity.namespace.CUSTOMACTION") {
    extraValue = intent.getStringExtra("extraValueName");
    Log.e("AwseomeApp", "Extra value Recieved from intent : " + extraValue);
}

For the code in HTML, write an intent for launching the specific Activity, with the action your.activity.namespace.CUSTOMACTION, and your application package name your.activity.namespace. Your can also put some extra in the intent. For example intent.putExtra("extraValueName", "WOW"). Then get the required URL by printing the value of intent.toUri(Intent.URI_INTENT_SCHEME) in the Log. It should look like :

intent:#Intent;action=your.example.namespace.CUSTOMACTION;package=your.example.namespace;component=your.example.namespace/.activity.YourActivity;S.extraValueName=WOW;end

So your HTML code should look like :

<a href="intent:#Intent;action=your.example.namespace.CUSTOMACTION;package=your.example.namespace;component=your.example.namespace/.activity.YourActivity;S.extraValueName=WOW;end">
    Launch App
</a>

This is as per what @hackbod suggested in here and this page from developers.google.com.

Community
  • 1
  • 1
abhishek89m
  • 261
  • 3
  • 6
7

Depending on your intent filter this link should work:

<a href="http://mydomain.com/launch">start my app</a>

But you should note that the android system will ask the user if your app or any other browser should be started.

If you want to avoid this implement a custom protcol handler. So just your app will listen for that and the user won't get the intent chooser.

Try to add this data intent:

<data android:scheme="mycoolapp" android:host="launch" />

With the code above this link should work:

<a href="mycoolapp://launch">start my app</a>
rekire
  • 47,260
  • 30
  • 167
  • 264
  • that works. But it offers the chooser. ie - open with browser or with app... what I'm trying to do is not have that show up. – Chris Mar 24 '13 at 09:29
  • Ill try this when I get a sec. However, android discourages custom schemes/namespaces. So I'd like to get this done the recommended way. – Chris Mar 24 '13 at 21:06
  • this is the best answer, and it works. I still would like to know how to do it with intent uris. but hey, this works for now :-) – Chris Mar 24 '13 at 22:28
5

I needed a small change to abhishek89m'a answer to make this work.

<a href="intent:#Intent;action=your.example.namespace.CUSTOMACTION;package=your.example.namespace;component=your.example.namespace/.YourActivity;S.extraValueName=WOW;end">
    Launch App
</a>

I removed ".activity" after the slash in component name.

And I want to add, that custom action is probably the best answer to this problem if you don't want the app chooser to show up.

p.s. I would add this as comment, but I'm a new user and I don't have enough reputation points.

robal1991
  • 51
  • 1
  • 3
2
<a href="your.app.scheme://other/parameters/here">

This link on your browser will launch the app with the specific schema like that on your intent

<intent-filter>
<data android:scheme="your.app.scheme" />
<action android:name="android.intent.action.VIEW" />
</intent-filter>
dotmido
  • 1,374
  • 3
  • 13
  • 29