我已将深层链接集成到我的文章应用中,并将此代码添加到我的艺术细节网页中。
<link rel="alternate"
href="android-app://com.example.android/myapp" />
当我在谷歌搜索文章并点击文章时,它会转到我的应用程序
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>
答案 0 :(得分:0)
这可能是由于AndroidManifest中为您的活动定义的意图过滤器,请分享看起来像这样的文章:
$dbh = new PDO('sqlite:contact.s3db');
然后我从点击的链接中获取我的东西:
<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>
我的深层链接URI如下所示:
// 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);
http://www.mywebsite.com/?action=1&nmbr=09981122341088&zip=11000
http://www.mywebsite.com/?action=1&num=09981122341088
随意查看this link