Make a link in the Android browser start up my app?

前端 未结 9 1125
小鲜肉
小鲜肉 2020-11-21 22:06

Is it possible to make a link such as:

click me!

cause my Anton app to start

9条回答
  •  不知归路
    2020-11-21 22:58

    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:

    Go to register.java
    

    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);
            }
    

提交回复
热议问题