Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to open Android App from external browsing

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces how to open Android App from external browsing related knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe you will have something to gain after reading this article on how to open Android App from external browsing, let's take a look at it.

First of all, let's take a look at the code on the browser, and this is where we jump from the page to open app.

Browser opens APP test opens APP new Mlink ({mlink: "Aa2F", button: document.querySelector ('axibtnOpenApp'), autoLaunchApp: false, autoRedirectToDownloadUrl: true, downloadWhenUniversalLinkFailed: false, inapp: true, params: {storyBoardKey:'DetailsActivity', storyBoardId:'ProductDetail' Name:'TwoActivity', productId:'1454456156'}})

Mlink: "Aa2F". This Aa2F is the mlink at the end of a short link we configured on the magic window. For example, my short link is: http://a.mlinks.cc/Aa2F.

Button: document.querySelector ('axibtnOpenApp')

AutoLaunchApp: false

AutoRedirectToDownloadUrl: true

DownloadWhenUniversalLinkFailed: false

Inapp: true

All these are explained on the official website, so I won't explain them; params is the parameter we want to pass.

All right, now it's a critical moment, and that's our configuration on app. Let's take a look at my project directory:

First pour the magic window package in, and then configure it on gradle. Mine is configured as follows:

Apply plugin: 'com.android.application'apply plugin:' me.tatarka.retrolambda'android {compileSdkVersion 24 buildToolsVersion "24.0.0" defaultConfig {applicationId "com.wingsofts.magicwindowdemo" minSdkVersion 15 targetSdkVersion 24 versionCode 1 versionName "1.0"} buildTypes {release {minifyEnabled false proguardFiles getDefaultProguardFile ('proguard-android.txt') 'proguard-rules.pro'}} compileOptions {targetCompatibility 1.8 sourceCompatibility 1.8}} dependencies {compile fileTree (dir:' libs' Include: ['* .jar']) testCompile 'junit:junit:4.12' compile' com.android.support:appcompat-v7:24.1.1' compile "io.reactivex:rxandroid:1.2.0" compile "io.reactivex:rxjava:1.1.7" compile (name: 'MagicWindowSDK', ext:' aar')} repositories {flatDir {dirs' libs'}}

Then take a look at the Myapp page. Mine goes like this:

Package com.wingsofts.magicwindowdemo;import android.app.Application;import com.zxinsight.Session;public class MyApp extends Application {@ Override public void onCreate () {super.onCreate (); Session.setAutoSession (this);}}

The role of the session here is to get the activity.

The MainActivity page looks like this:

Package com.wingsofts.magicwindowdemo;import android.content.Intent;import android.os.Bundle;import android.support.v7.app.AppCompatActivity;import android.view.View;public class MainActivity extends AppCompatActivity {@ Override protected void onCreate (Bundle savedInstanceState) {super.onCreate (savedInstanceState); setContentView (R.layout.activity_main);} public void onClick (View v) {startActivity (new Intent (this, DetailsActivity.class));}}

Activity_main:

The above two pages have nothing to introduce, very ordinary two pages.

DetailsActivity page:

Package com.wingsofts.magicwindowdemo;import android.os.Bundle;import android.support.v7.app.AppCompatActivity;public class DetailsActivity extends AppCompatActivity {@ Override protected void onCreate (Bundle savedInstanceState) {super.onCreate (savedInstanceState); setContentView (R.layout.activity_details);}}

Activity_details layout:

TwoActivity page:

Package com.wingsofts.magicwindowdemo;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;public class TwoActivity extends AppCompatActivity {@ Override protected void onCreate (Bundle savedInstanceState) {super.onCreate (savedInstanceState); setContentView (R.layout.activity_two);}}

The corresponding layout is activity_two:

The following page is important, and basically all the important code is concentrated here:

Package com.wingsofts.magicwindowdemo;import android.content.Context;import android.content.Intent;import android.net.Uri;import android.os.Bundle;import android.support.v7.app.AppCompatActivity;import com.zxinsight.MLink;import com.zxinsight.MWConfiguration;import com.zxinsight.MagicWindowSDK;import com.zxinsight.mlink.MLinkCallback;import com.zxinsight.mlink.MLinkIntentBuilder;import java.util.Iterator;import java.util.Map;import java.util.concurrent.TimeUnit;import rx.Observable;import rx.android.schedulers.AndroidSchedulers Public class SplashActivity extends AppCompatActivity {private String DEMONAME = "com.wingsofts.magicwindowdemo"; @ Override protected void onCreate (Bundle savedInstanceState) {super.onCreate (savedInstanceState); setContentView (R.layout.activity_splash); initSDK (); / / initialize SDK registerLinks (this); / / register SDK initMLink ();} public void initMLink () {Intent intent = getIntent (); Uri mLink = intent.getData () / / if it comes from the browser, route if (mLink! = null) {MLink.getInstance (this) .router (this, mLink); finish ();} else {/ / otherwise perform the original operation go2MainActivity () }} / / Register SDK public void registerLinks (Context context) {MLink.getInstance (context) .registerDefault (new MLinkCallback () {@ Override public void execute (Map paramMap, Uri uri, Context context) {/ / default route if there is no match then jump to MainActivity for your home page MLinkIntentBuilder.buildIntent (paramMap, context, MainActivity.class) }}); / / testKey: the key of mLink, the unique identity of mLink, used for routing operations MLink.getInstance (context) .register ("productDetail", new MLinkCallback () {public void execute (Map paramMap, Uri uri, Context context) {/ /! Note that there is a hole here. If there is a delay in your SplashActivity transfer, the delay must be greater than the former jump time Observable.timer (1050, TimeUnit.MILLISECONDS) .subscribe (aVoid-> {/ / MLinkIntentBuilder.buildIntent (paramMap, context, Class.forName (name)). String name = (String) paramMap.get ("name"); Intent intent = new Intent (); intent.setClassName (context, DEMONAME + "." + name); startActivity (intent);});}) } / / initialize the magic window SDK public void initSDK () {MWConfiguration config = new MWConfiguration (this); config.setDebugModel (true) / / page with Fragment. For more information, please see 2.2.2 .setPageTrackWithFragment (true) / / set the sharing method. If there is an integrated sharesdk before, you can enable .setShareplatform (MWConfiguration.ORIGINAL); MagicWindowSDK.initSDK (config) here. } public void go2MainActivity () {/ / delay 1 second to forward Observable.timer (1, TimeUnit.SECONDS) .subscrieOn (AndroidSchedulers.mainThread ()) .subscribe (aLong-> {startActivity (new Intent (this, MainActivity.class)); finish ();}) } private void StartActivity (Map paramMap, Context context, Class clazz) {Intent intent = new Intent (context, clazz); intent.addFlags (Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); if (paramMap! = null) {Iterator iter = paramMap.entrySet () .iterator () While (iter.hasNext ()) {Map.Entry entry = (Map.Entry) iter.next (); String key = (String) entry.getKey (); String val = (String) entry.getValue (); intent.putExtra (key, val);}} context.startActivity (intent);}}

Layout:

I have comments on the above code, and it should be noted here that if you pass parameters, you must configure them, or there will be an error.

This is the end of the article on "how to start Android App from external browsing". Thank you for reading! I believe you all have a certain understanding of the knowledge of "how to open Android App from external browsing". If you want to learn more, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report