Android Operations HTML Open Other App_android

Source: Internet
Author: User

Now Android programmers are more and more, even in some areas of oversupply situation, from a large background, Android's eco-chain will gradually become rational, and will continue to update the talent and development tools, a few years ago, Eclipse is unusually hot, now Android With a good experience, studio more and more people have moved to Android studio to develop, so this is also a manifestation of diversity, nonsense so much, I want to express is that people are not a problem, it is important that they have the ability to do this job, non-stop learning new technology , update yourself.

Now, let's talk about how to open the phone in the HTML app, this demand is now used more and more widely, such as Taobao, Alipay payment, etc., are used to this function, but how to achieve it, I use webview to simulate such a function, First look at the code inside the HTML:

<! DOCTYPE html> 
 
 

Yes, you did not read the wrong, so a few lines of code, no use of JS, nor use of CSS, (/a) tag is a hyperlink tag, this is believed to be a bit of the basis of the people are understood, it is important to look at the contents of the hyperlink: xiaopinggaiblog:// Xiappinggai/open, this is my own custom, first look at the application we want to open the registration file inside the writing:

<activity
      android:name= ". Mainactivity "
      android:excludefromrecents=" true "
      android:label=" @string/app_name "
      android: screenorientation= "Portrait" >

      <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"/>
        <category android:name= " Android.intent.category.DEFAULT "/>
        <data
          android:pathprefix="/xiappinggai/open "
          android: Scheme= "Xiaopinggaiblog"/>
      </intent-filter>
    </activity>

My simulation here is to open another program's main interface, see the following an intent filter, here is a < data/> tag, the contents of this tag:

<data android:pathprefix= "/xiappinggai/open"
Android:scheme= "Xiaopinggaiblog"/>

The Pathprefix property specifies only a partial path, which matches the initial part of the path in the intent object.
The Scheme property is used to set the scheme portion of the URI. It is the most basic attribute set for the specified URI, and at least one scheme property must be set for the filter, otherwise, the other URI attributes are meaningless.

This is so configured, it can be perfect to open other apps, while some browsers also support this function, if the test occurs when not open, then you can consider changing a browser test.

Next, let's look at how to pass the data to that application. In fact, it is not difficult, only need to change the URL on the line: specific as follows:

Xiaopinggaiblog://xiappinggai/open?data=xiaopinggaiblog

What if you have to wear more than one parameter? In fact, you can use the & symbol to connect, so write:

Xiaopinggaiblog://xiappinggai/open?data=xiaopinggaiblog&arga=value

So how do you receive it in that application, which is actually a few lines of code, we write in the activity that is going to receive the data:

   Uri uridata = This.getintent (). GetData ();
      if (uridata!=null) {
        String MyData = uridata.getqueryparameter ("data");
      }

This can be written to get the data, but there is also a problem, when the app to open is not installed, then click on Open app will be an error, which will affect the interactive experience, so we can do this:

Mweb.setwebviewclient (New Webviewclient () {
      @Override public
      void Onreceivederror (webview view, int errorcode ,
          string Description, String failingurl) {
        mweb.loadurl ("file:///android_asset/html2.html");
        Toast.maketext (Mainactivity.this, "No this App", 0). Show ();
      }

    

This is done, and this is what happens when a Web page fails to load. In addition to this hint, we can also let him jump to the app's download address, and so on a series of operations they want.

All right, all the code is here.

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.