如何在手机浏览器中打开安卓APP

新建一个OpenActivity,在清单文件加入一下代码
<activity android:name=".OpenActivity" android:exported="true" android:enabled="true" >
    <intent-filter android:autoVerify="true">
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data android:host="www.test.com" android:scheme="myscheme" />
    </intent-filter>
</activity>

新建一个html文件,在body标签加入以下代码

<a href="myscheme://www.test.com/open">启动应用</a>

或者在跨APP调起

            Intent intent = new Intent();
            intent.setAction(Intent.ACTION_VIEW);
            intent.setData(Uri.parse("myscheme://www.test.com/open"));
            intent.addCategory(Intent.CATEGORY_DEFAULT);

在OpenActivity中获取来源的数据

android.content.Intent intent = getIntent();
android.net.Uri uri = intent.getData();
String scheme = uri.getScheme();
String host = uri.getHost();
int port = uri.getPort();
String path = uri.getPath();
String query = uri.getQuery();
Log.d("debug", "scheme->" + scheme);//输出:scheme->buyuphk
Log.d("debug", "host->" + host);//输出:host->www.buyuphk.com
Log.d("debug", "port->" + port);//输出:port->-1
Log.d("debug", "path->" + path);//输出:path->/test
Log.d("debug", "query->" + query);//输出:query->null

之后可根据path做进一步的逻辑操作

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值