Android 网页打开app(或者打开指定页面)而且接收参数

网页打开app
现实描述场景:
一、短信通知中通知内容,好比信息中一个咨询详情,流程步骤,信息中的地址打开的是一个网页,网页打开就指定app或者app中的指定页面
html代码html

  <html>  
      
        <head>  
      
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">  
          
            <title>Insert title here</title>  
      
        </head>  
      
        <body>  
      
            <a href="m://任意规定,同intent-filter一致便可/?text=android">打开app</a><br/>  
      
        </body>  
      
    </html>  

而后再app的AndroidManifest.xml中配置代码,若是只想打开app即在app的启动页面便可,若是想要再指定页面打开而且接收参数,再对应的activity中配置intent-filterandroid

<activity android:name="指定页面">
            <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:host="任意规定,同intent-filter一致便可"
                    android:scheme="m" />
            </intent-filter>
        </activity>

接收参数操做再app的onCreate中app

 //测试获取网页打开app传递的参数
        Uri uri=getIntent().getData();
        if (uri!=null){
            //获取传递的参数
            Toast.makeText(mContext, "网页传递的参数:"+uri.getQueryParameter("text"), Toast.LENGTH_SHORT).show();
            Log.e("qzinfodetails","-------------网页传递的参数:"+ uri.getQueryParameter("text"));
        }
    }

这样便可打开指定页面而且接收参数测试

相关文章
相关标签/搜索