How Android jumps from the outside into the app

Source: Internet
Author: User


Blog from: http://blog.csdn.net/liuxian13183, reprint annotated source! All Rights Reserved!


This problem solved two days, because there is no complete solution on the net, after the solution to share to everyone!

There are two functions to solve this problem:

1, do not open the app directly into a page

2, realize the app to share the external, while the external access to the app's closed loop.

This topic can be divided into two aspects, on the one hand from access to the app, on the other hand, from the Web page into the app.

let's take http://my.oschina.net/liucundong/blog/354029 as an example.

mainly through scheme, host, PATH, Pathprefix and other data information to differentiate

Two programs need to add intent-filter information to the activity that jumps to, for example

<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= "Cundong" android:host= "Splash"/>

</intent-filter>

First, let's go to the app, scene: Share content from the app, and then open the app directly.

The first step, registered public platform, the relevant enterprise information, download links, logos, etc. are completed

The second step, share the use of Wxappextendobject, the link URL to assign value to extinfo

The third step, when the Onreq method of the Iwxapieventhandler interface is Req.gettype () =constantsapi.command_showmessage_from_wx, initiates your jump

The fourth step, the need for data to jump, where the data from, from the Wxentryactivity class OnCreate method Getintent Object

This is the end of the app entry.

-------------------I'm a split line------------------------

Then the web-side, due to the limitations of webview, such as Weibo, such as the use of this control, so can only share the Web page, and then into the app.

The principle is as follows:

<div>
<a id= "J-call-app" href= "javascript:;" class= "label" > Open now &gt;&gt;</a>
<input id= "J-download-app" type= "hidden" name= "Storeurl" value= "http://apk.hiapk.com/appinfo/com.tmall.wireless ">
</div>

<script>
(function () {
var ua = Navigator.userAgent.toLowerCase ();

var T;
var url=document.location;
var config = {
/*scheme: Must */
Scheme_ios: ' cundong://',
Scheme_adr: ' Cundong://splash ',
Download_url:document.getElementById (' J-download-app '). Value,
timeout:600
};

function Openclient () {
var startTime = Date.now ();

var IFR = document.createelement (' iframe ');

alert (CONFIG.SCHEME_ADR);
IFR.SRC = Ua.indexof (' os ') > 0? CONFIG.SCHEME_IOS:CONFIG.SCHEME_ADR;
Ifr.style.display = ' None ';
Document.body.appendChild (IFR);

var t = setTimeout (function () {
var endTime = Date.now ();

if (!starttime | | Endtime-starttime < config.timeout-200) {
window.location = Config.download_url;
} else {
Window.location.href=ifr.src.replace ("http://", "cundong://");;
}
}, Config.timeout);



Window.onblur = function () {
Cleartimeout (t);
}
}
Window.addeventlistener ("domcontentloaded", function () {
document.getElementById ("J-call-app"). AddEventListener (' click ', Openclient,false);

}, False);
})()
</script>

Click to open four words, the execution of a JS, within the time limit, if you can open the app is open, otherwise go to the download page

The basic idea to solve this problem is this, welcome to exchange discussion!



How Android jumps from the outside into the app

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.