Android:scheme jump to App app to assign activity via URI

Source: Internet
Author: User

Recently, the company has a demand, click on the third-party app's H5 page and then jump directly into the app, such as the browser to open a H5 page, and then click on a link directly to the application of a designated activity, after the study found that the implementation is pretty easy, the following method.

First, in the androidmanifest.xml inside the configuration, in the corresponding activity plus a intent-filter, as follows:

<application android:icon= "@drawable/ic_launcher" android:label= "@string/app_name" Android:theme= " @style/apptheme "> <activity android:name=".                Mainactivity "android:label=" @string/title_activity_main "> <intent-filter> <action android:name= "Android.intent.action.MAIN"/> <category android:name= "Android.intent.catego Ry. LAUNCHER "/> </intent-filter> <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= "Parache S "/> </intent-filter> </activity> </application>

Next, add the relevant parsing code to the corresponding activity, as follows:

@Override public void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);        Setcontentview (R.layout.activity_main);        Intent Intent = Getintent ();        String action = Intent.getaction ();        if (Intent.ACTION_VIEW.equals (ACTION)) {uri uri = Intent.getdata ();                if (uri! = null) {String host = Uri.gethost ();                String datastring = intent.getdatastring ();                String id = uri.getqueryparameter ("id");                String path = Uri.getpath ();                String path1 = Uri.getencodedpath ();                String queryString = Uri.getquery ();                LOG.D ("Alex", "Host:" +host);                LOG.D ("Alex", "datastring:" + datastring);                LOG.D ("Alex", "ID:" + ID);                LOG.D ("Alex", "Path:" + path);                LOG.D ("Alex", "path1:" + path1);            LOG.D ("Alex", "queryString:" + queryString); }        }    }

Look at the log case, as follows:

host:schemedemodatastring:paraches://schemedemo/get/info?id=10000id:10000path:/get/infopath1:/get/ infoquerystring:id=10000

Simple Web page, this page can be opened with a browser, and then click the Jump Link:

<a href= "paraches://schemedemo/get/info?id=10000" >open android app</a>

After the above steps on OK, is not very easy ah, but I believe there may still be a small partner will get lost, here upload a project demo, this page on its own set up, I will not upload, link as follows:

http://download.csdn.net/detail/msn465780/9516335

Click to open link


Android:scheme jump to App app to assign activity via URI

Related Article

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.