欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

如何從外部瀏覽開(kāi)啟Android App

 更新時(shí)間:2021年06月08日 14:32:30   作者:handsome黃  
從瀏覽器中點(diǎn)擊某個(gè)按鈕,如果手機(jī)上裝有相應(yīng)的app,則直接開(kāi)啟app,并且到相對(duì)的頁(yè)面。如果沒(méi)有裝該app,則會(huì)到相應(yīng)的下載app的界面。這樣的功能怎么實(shí)現(xiàn)呢,本文帶著大家來(lái)看看如何實(shí)現(xiàn)。

這里主要用的是第三方的東西,就是魔窗中的mlink功能。想了解魔窗的朋友就到官網(wǎng)去看看吧。在這里我說(shuō)一下我通過(guò)魔窗是怎么實(shí)現(xiàn)的。

首先我們看一下瀏覽器上面的代碼,這個(gè)就是我們從該頁(yè)面上跳轉(zhuǎn)打開(kāi)app。

<html>
    <head>
        <title>瀏覽器打開(kāi)APP測(cè)試</title>
        <script src="https://cdn.bootcss.com/jquery/3.1.1/jquery.js"></script>
        <script src="https://static.mlinks.cc/scripts/dist/mlink.min.js"></script>
    </head>
    <body>
        <a id="btnOpenApp">打開(kāi)APP</a>
   <script>
    new Mlink(
        {
        mlink: "Aa2F",
        button: document.querySelector('a#btnOpenApp'),
        autoLaunchApp : false,
        autoRedirectToDownloadUrl: true,
        downloadWhenUniversalLinkFailed: false,
        inapp : true,
        params: {
              storyBoardKey:'DetailsActivity',
              storyBoardId:'ProductDetail',
              name:'TwoActivity',
              productId:'1454456156'

              }
        })
   </script>
    </body>
</html>

mlink: "Aa2F",這個(gè)Aa2F就是我們?cè)谀Т吧吓渲玫囊粋€(gè)短鏈接最后面的mlink,比如,我的短鏈接是:http://a.mlinks.cc/Aa2F

button: document.querySelector('a#btnOpenApp'),

autoLaunchApp : false,

autoRedirectToDownloadUrl: true,

downloadWhenUniversalLinkFailed: false,

inapp : true,

這些在官網(wǎng)上都有解釋,我就不解釋了;params就是我們要傳遞的參數(shù)。

好了,現(xiàn)在到了關(guān)鍵時(shí)刻了,就是我們app上面的配置了,先看我的項(xiàng)目目錄:

先把魔窗這個(gè)包倒進(jìn)來(lái),然后在gradle上進(jìn)行配置,我的是這樣配置的:

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'
    }
}

然后在看看Myapp頁(yè)面,我的是這樣的:

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

這里的session的作用是獲取到活動(dòng)。

MainActivity頁(yè)面是這樣的:

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:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.wingsofts.magicwindowdemo.MainActivity"
    >

  <Button
      android:layout_centerInParent="true"
      android:onClick="onClick"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="點(diǎn)我去詳情頁(yè)"
      />
</RelativeLayout>

上面這兩個(gè)頁(yè)面就沒(méi)什么好介紹的了,很平常的兩個(gè)頁(yè)面。

DetailsActivity頁(yè)面:

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布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.wingsofts.magicwindowdemo.DetailsActivity"
    >
<TextView
    android:text="我是詳情頁(yè)"
    android:textSize="30sp"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    />
</RelativeLayout>

TwoActivity頁(yè)面:

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

對(duì)應(yīng)得布局是activity_two:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.wingsofts.magicwindowdemo.TwoActivity">


    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="我是第二個(gè)頁(yè)面"
        android:textSize="40sp"
        />

</RelativeLayout>

下面這一個(gè)頁(yè)面很重要,基本上所有的重要代碼都集中在這里:

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();//初始化SDK
        registerLinks(this);//注冊(cè)SDK
        initMLink();


    }


    public void initMLink() {
        Intent intent = getIntent();
        Uri mLink = intent.getData();
        //如果從瀏覽器傳來(lái) 則進(jìn)行路由操作
        if (mLink != null) {
            MLink.getInstance(this).router(this, mLink);
            finish();
        } else {
            //否則執(zhí)行原本操作
            go2MainActivity();
        }
    }


    //注冊(cè)SDK
    public void registerLinks(Context context) {
        MLink.getInstance(context).registerDefault(new MLinkCallback() {
            @Override
            public void execute(Map paramMap, Uri uri, Context context) {
                //默認(rèn)的路由 如果沒(méi)有匹配則轉(zhuǎn)跳到 MainActivity 為你的首頁(yè)
                MLinkIntentBuilder.buildIntent(paramMap, context, MainActivity.class);
            }
        });


        // testKey:  mLink 的 key, mLink的唯一標(biāo)識(shí),用于進(jìn)行路由操作
        MLink.getInstance(context).register("productDetail", new MLinkCallback() {
            public void execute(Map paramMap, Uri uri, Context context) {

                //!!!!!!!!注意 此處有坑,如果你的SplashActivity轉(zhuǎn)跳有延遲,那么在此處轉(zhuǎn)跳的延遲必須大于前者轉(zhuǎn)跳時(shí)間
                Observable.timer(1050, TimeUnit.MILLISECONDS)
                        .observeOn(AndroidSchedulers.mainThread())
                        .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);
                        });
            }
        });
    }

    //初始化魔窗SDK
    public void initSDK() {
        MWConfiguration config = new MWConfiguration(this);
        config.setDebugModel(true)
                //帶有Fragment的頁(yè)面。具體查看2.2.2
                .setPageTrackWithFragment(true)
                //設(shè)置分享方式,如果之前有集成sharesdk,可在此開(kāi)啟
                .setSharePlatform(MWConfiguration.ORIGINAL);
        MagicWindowSDK.initSDK(config);
    }


    public void go2MainActivity() {

        //延遲1秒轉(zhuǎn)跳
        Observable.timer(1, TimeUnit.SECONDS)
                .observeOn(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);

    }


}

布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.wingsofts.magicwindowdemo.SplashActivity"
    >
<TextView
    android:textSize="30sp"
    android:text="我是引導(dǎo)頁(yè)!!"
    android:layout_centerInParent="true"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    />
</RelativeLayout>

代碼上面的我都有注釋,在這里需要注意的是,傳遞參數(shù)的話一定要配置好,否則會(huì)出現(xiàn)錯(cuò)誤。

以上就是如何從外部瀏覽開(kāi)啟Android App的詳細(xì)內(nèi)容,更多關(guān)于從外部瀏覽開(kāi)啟Android App的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • android ImageView 的幾點(diǎn)經(jīng)驗(yàn)總結(jié)

    android ImageView 的幾點(diǎn)經(jīng)驗(yàn)總結(jié)

    本篇文章是對(duì)android中ImageView的使用技巧進(jìn)行了幾點(diǎn)經(jīng)驗(yàn)總結(jié),需要的朋友參考下
    2013-06-06
  • Android自定義底部彈出框ButtomDialog

    Android自定義底部彈出框ButtomDialog

    這篇文章主要為大家詳細(xì)介紹了Android自定義底部彈出框ButtomDialog,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-11-11
  • Android中切換到主線程執(zhí)行的方法

    Android中切換到主線程執(zhí)行的方法

    這篇文章主要介紹了Android中切換到主線程執(zhí)行的方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2021-03-03
  • 詳解ViewBinding用法

    詳解ViewBinding用法

    這篇文章主要介紹了ViewBinding用法,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2023-03-03
  • Android編程實(shí)現(xiàn)3D立體旋轉(zhuǎn)效果的實(shí)例代碼

    Android編程實(shí)現(xiàn)3D立體旋轉(zhuǎn)效果的實(shí)例代碼

    這篇文章主要介紹了Android編程實(shí)現(xiàn)3D立體旋轉(zhuǎn)效果的實(shí)例代碼,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2018-05-05
  • Kotlin中的handler如何避免內(nèi)存泄漏詳解

    Kotlin中的handler如何避免內(nèi)存泄漏詳解

    Handler,我們已經(jīng)相當(dāng)熟悉了,而且經(jīng)常用得不亦樂(lè)乎,但就是因?yàn)樘煜ち?,才?huì)偶爾被它反捅一刀,血流不止,下面這篇文章主要給大家介紹了關(guān)于Kotlin中handler如何避免內(nèi)存泄漏的相關(guān)資料,需要的朋友可以參考下。
    2017-12-12
  • Ubuntu中為Android實(shí)現(xiàn)Application Frameworks層增加硬件訪問(wèn)服務(wù)

    Ubuntu中為Android實(shí)現(xiàn)Application Frameworks層增加硬件訪問(wèn)服務(wù)

    本文主要介紹Android實(shí)現(xiàn) Application Frameworks層增加硬件訪問(wèn)服務(wù),這里對(duì)實(shí)現(xiàn)增加硬件訪問(wèn)服務(wù)的功能做出了詳細(xì)的工作流程,并提供示例代碼,有需要的小伙伴參考下
    2016-08-08
  • Android 動(dòng)態(tài)高斯模糊效果教程

    Android 動(dòng)態(tài)高斯模糊效果教程

    本文主要介紹Android 動(dòng)態(tài)高斯模糊效果教程,這里整理了詳細(xì)的資料及實(shí)例實(shí)現(xiàn)代碼,有興趣的小伙伴可以參考下
    2016-09-09
  • Android自定義條形對(duì)比統(tǒng)計(jì)圖

    Android自定義條形對(duì)比統(tǒng)計(jì)圖

    這篇文章主要為大家詳細(xì)介紹了Android自定義條形對(duì)比統(tǒng)計(jì)圖,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-07-07
  • Android Handler實(shí)現(xiàn)閃屏頁(yè)倒計(jì)時(shí)代碼

    Android Handler實(shí)現(xiàn)閃屏頁(yè)倒計(jì)時(shí)代碼

    這篇文章主要介紹了Android Handler實(shí)現(xiàn)閃屏頁(yè)倒計(jì)時(shí)代碼,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2020-08-08

最新評(píng)論