Android 網頁打開app(或者打開指定頁面)並且接收參數


網頁打開app
現實描述場景:
1、短信通知中通知內容,比如信息中一個咨詢詳情,流程步驟,信息中的地址打開的是一個網頁,網頁打開就指定app或者app中的指定頁面
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-filter

<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傳遞的參數
        Uri uri=getIntent().getData();
        if (uri!=null){
            //獲取傳遞的參數
            Toast.makeText(mContext, "網頁傳遞的參數:"+uri.getQueryParameter("text"), Toast.LENGTH_SHORT).show();
            Log.e("qzinfodetails","-------------網頁傳遞的參數:"+ uri.getQueryParameter("text"));
        }
    }

這樣即可打開指定頁面並且接收參數

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM