本文最后编辑于 前,其中的内容可能需要更新。
需求:网页上一个链接,点击后会唤醒手机内响应的app,打开指定APP的功能页面。
方法:在AndroidManifest.xml里面对需要打开的页面设置action,两个category, data
1 2 3 4 5 6 7 8 <activity android:name =".MainActivity2" > <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:scheme ="fshao" android:host ="my.app" android:pathPrefix ="/openwith" /> </intent-filter > </activity >
一会儿url请求格式是: scheme://host/path?传的参数
对应页面获取数据:
kotlin 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 val uri = intent.data if (uri != null ){ val url = uri.toString() val scheme = uri.scheme val host = uri.host val port = uri.port val path = uri.path val pathSegments = uri.pathSegments val query = uri.queryParameterNames for (key in query){ showText = showText + key + ":" + uri.getQueryParameter(key) + "\n" } tv_show.setText(showText) }
java 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 Uri uri = getIntent().getData(); if (uri != null ) { String url = uri.toString(); Log.e(TAG, "url: " + uri); String scheme = uri.getScheme(); Log.e(TAG, "scheme: " + scheme); String host = uri.getHost(); Log.e(TAG, "host: " + host); int port = uri.getPort(); Log.e(TAG, "host: " + port); String path = uri.getPath(); Log.e(TAG, "path: " + path); List<String> pathSegments = uri.getPathSegments(); String query = uri.getQuery(); Log.e(TAG, "query: " + query); String goodsId = uri.getQueryParameter("goodsId" ); Log.e(TAG, "goodsId: " + goodsId); }
本文章参考的博客:https://www.cnblogs.com/chaoyuehedy/p/9004224.html
本文也是看这个博客,记录一下。