3

I want my application to be opened from a link, by following the directions of Make a link in the Android browser start up my app?. Well, it works fine (most of the time.... this is the reason I am asking for help).

My html link is

<a href="intent:#Intent;action=com.mark.MY_ACTION;end">Open Application</a>

My intent filter is in the form

<intent-filter>
     <action android:name="com.mark.MY_ACTION"/>
     <category android:name="android.intent.category.DEFAULT">
     <category android:name="android.intent.category.BROWSABLE">
</intent-filter>

So far so good (I hope). It works fine from m-o-s-t of the browsers.

To test the above I wrote a demo activity

final WebView webview = new WebView(this); 
setContentView(webview); 
webview.loadUrl("http://www.myhomepage.com/"); 

The page http://www.myhomepage.com/ has some custom links/hrefs (including the inent one).

Pressing regular links opens me a browser with those links, but pressing my "special link" (the intnet one) opens a 404 page

Web page not available
intent:#Intent;action=com.mark.MY_ACTION;end
might be temporarily down....

While Diane mentioned in The above link,

They allow you to direct the launch to only your app without the user having the option of instead going to the browser or any other app.

Community
  • 1
  • 1
Omer
  • 335
  • 1
  • 4
  • 8
  • I believe here's what you're looking for http://stackoverflow.com/questions/2958701/launch-custom-android-application-from-android-browser/2958870#2958870 – Mars Sep 27 '11 at 14:34
  • 1
    This is one approach using scheme, but as Diane (my guru) said "We strongly discourage people from using their own schemes, unless they are defining a new world-wide internet scheme." I want to use intent:.... – Omer Sep 27 '11 at 14:42

3 Answers3

1

Add this code in Manifest.xml

<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:host="www.parag-chauhan.com"
        android:path="/test"
        android:scheme="http" />
</intent-filter>

For test create another project and run below code

Intent i = new Intent(
    Intent.ACTION_VIEW , Uri.parse("http://www.parag-chauhan.com/test")
);
startActivity(i);

You can also pass parameter in link. For more info, see my blog post Make a link in the Android browser start up my app?

Parag Chauhan
  • 35,760
  • 13
  • 86
  • 95
1

your Intent Filter is some same as mentioned by Diana

<activity android:name=".AntonWorld"
      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>
        <data android:scheme="anton" />
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.BROWSABLE" />
        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</activity>

So yours should be like:

<intent-filter> 
    <data android:scheme="com.mark.MY_ACTION"/>
    <category android:name="android.intent.category.DEFAULT"/>
    <category android:name="android.intent.category.BROWSABLE"/>
</intent-filter>

Did not test if android.intent.category.VIEW is required. Let me know if it works.

AliDeo
  • 169
  • 6
  • Diana also says that she had some issue with the order of the subelements. Maybe you need android.intent.category.BROWSEABLE before android.intent.category.Default. – AliDeo Sep 27 '11 at 14:32
  • I don't want my url to be anton://www.....com, I want to forward an implict intent to my application. – Omer Sep 27 '11 at 14:44
  • it will not be anton now as you have changed the following Intent Filter subelement: – AliDeo Sep 27 '11 at 14:47
  • and your link is `code`Open Application I think it should be Open Application, I will make a test class and check it as well. – AliDeo Sep 27 '11 at 14:51
  • What you are suggesting, is another approach. And it works pretty much the same as the "intent:" approach. Try using your approach from this browser http://code.google.com/p/zirco-browser/ – Omer Sep 27 '11 at 15:01
1

Try my simple trick:

        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            if(url.startsWith("classRegister:")) {                  
                Intent MnRegister = new Intent(getApplicationContext(), register.class); startActivity(MnRegister);
            }               
            view.loadUrl(url);
            return true;
        }

and my html link:

<a href="classRegister:true">Go to register.java</a>

or you can make < a href="classRegister:true" > <- "true" value for class filename

however this script work for mailto link :)

        if (url.startsWith("mailto:")) {
            String[] blah_email = url.split(":");
            Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
            emailIntent.setType("text/plain");
            emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{blah_email[1]});
            emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, what_ever_you_want_the_subject_to_be)");
            Log.v("NOTICE", "Sending Email to: " + blah_email[1] + " with subject: " + what_ever_you_want_the_subject_to_be);
            startActivity(emailIntent);
        }
IRvanFauziE
  • 823
  • 11
  • 16