Android - 集成华为推送之scheme协议跳转

本文介绍了Android中如何集成华为推送,并详细阐述了url scheme协议的格式和配置步骤,包括注册DemoActivity、通过scheme启动app、DemoActivity接收参数的方法。同时,讨论了launchMode对onNewIntent的影响,以及action和category在Intent过滤器中的作用。最后提到了h5页面通过scheme协议唤醒app的场景。
摘要由CSDN通过智能技术生成

一、url scheme协议格式:


 一个完整的完整的 url scheme协议格式由scheme、host、port、path和query组成,其结构如下所示: 
 
 scheme://host:port/path?query

 举例:
 coolweather://com.coolWeather.android:8080/WeatherActivity?param1=flag1&param2=flag2
 coolweather://?param1=flag1&param2=flag2

二、 配置步骤:

1、参照如下配置注册DemoActivity


<activity
    android:name=".DemoActivity"
    android:launchMode="singleTask">
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <!--默认的Category-->
        <category android:name="android.intent.category.DEFAULT" />
        <!--指定该Activity能被浏览器安全调用-->
        <category android:name="android.intent.category.BROWSABLE" />

        <data
            android:host="[自定义]"
            android:path="[自定义]"
            android:port="[自定义]"
            android:scheme="[自定义]" />
        </intent-filter>
</activity>

 <!-- 举例
        <data
            android:host="com.coolweather.android"
            android:path="/WeatherActivity"
            android:port="8080"
             android:scheme="coolweather" />
        -->
        

2、通过scheme协议打开app


private void openOtherApp() {
    //方法1
    String uriString = "android://com.coolWeather.android:8080/WeatherActivity?param1=flag1&param2=flag2";
    Intent intent = new Intent();
    intent.setData(Uri.parse(uriString));
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(intent);

    //方法2
    String uriString2 = "android://com.coolWeather.android:8080/WeatherActivity?";
    Intent int
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值