[英]Android deep linking web url format error
我已將深層鏈接集成到我的文章應用程序中,並將此代碼添加到我的詳細資料網頁中。
<link rel="alternate"
href="android-app://com.example.android/myapp" />
當我在Google上搜索文章並單擊某篇文章時,它會轉到我的應用
String action = intent.getAction();
String data = intent.getDataString();
但是這里的數據變量是普通鏈接(www.myapp.com / ...),而不是格式化的(android-app:// ....)
為什么它像通常的鏈接一樣出現,卻沒有按照深層鏈接格式進行格式化?
我的清單文件上有意圖過濾器:
<activity
android:name="MyActivity"
android:configChanges="orientation|screenSize"
android:launchMode="singleTop">
<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="http"
android:host="www.myapp.com"
android:pathPrefix="" />
</intent-filter>
<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="http"
android:host="myapp"
android:pathPrefix="" />
</intent-filter>
</activity>
可能是由於您在AndroidManifest中為您的活動定義了意圖過濾器,請分享如下內容:
<activity
android:name=".ActivitySplash"
android:configChanges="orientation|screenSize|keyboardHidden"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:theme="@style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<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="http" android:host="www.mywebpage.com" android:pathPattern=".*" />
<data android:scheme="https" android:host="www.mywebpage.com" android:pathPattern=".*" />
<data android:scheme="http" android:host="127.0.0.1" android:pathPattern=".*" />
<data android:scheme="https" android:host="127.0.0.1" android:pathPattern=".*" />
<data android:scheme="http" android:host="my.webpage.com" android:pathPattern=".*" />
<data android:scheme="https" android:host="my.webpage.com" android:pathPattern=".*" />
</intent-filter>
</activity>
然后我從點擊的鏈接中得到了我的東西,像這樣:
// check if this intent is started via custom scheme link
if (intent != null && Intent.ACTION_VIEW.equals(intent.getAction())) {
Log.d("DEEPLINK", "Deep link data detected, initializing in deep link mode...");
Uri uri = intent.getData();
String origin = intent.getDataString();
//Uri uri2 = Uri.parse(Uri.encode(origin));
String actionString = uri.getQueryParameter("action"); // get 'action'
//fetch possible NUM variations: nmbr, num, arg
String pno_alias1 = uri.getQueryParameter("nmbr"); // get 'pno'
String pno_alias2 = uri.getQueryParameter("num"); // get 'pno'
String pno_alias3 = uri.getQueryParameter("arg"); // get 'pno'
String pno = (pno_alias1 == null) ? ( (pno_alias2 == null) ? (pno_alias3 == null ? null : pno_alias3) : pno_alias2 ) : pno_alias1;
importantNumber = pno;
//fetch possible zip variations: plz, zip
String zip_alias1 = uri.getQueryParameter("zip"); // get 'zip'
String zip_alias2 = uri.getQueryParameter("plz"); // get 'plz'
String zip = (zip_alias1 == null) ? ( (zip_alias2 == null) ? null : zip_alias2 ) : zip_alias1;
Toast.makeText(this, "Intent URI: " + uri + "\n\nAction: " + actionString + "\nPNO: " + pno + "\nZip: " + zip, Toast.LENGTH_SHORT).show();
Toast.makeText(this, "Parameter names: " + uri.getQueryParameterNames() + "\n\nOrigin string: " + origin, Toast.LENGTH_LONG).show();
if (actionString != null && !actionString.isEmpty())
deepLinkActionType = DeepLinkActionType.valueOf(Integer.valueOf(actionString));
Log.d("DEEPLINK", "deep link action type: " + deepLinkActionType + "\tPNO: " + pno + "\tZIP: " + zip);
我的Deeplink URI如下所示:
http://www.mywebsite.com/?action=1&nmbr=09981122341088&zip=11000
http://www.mywebsite.com/?action=1&num=09981122341088
http://www.mywebsite.com/?action=3
隨時查看此鏈接
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.