use*_*471 12 android firebase firebase-dynamic-links
我在我的设备上本地开发了一个Android应用程序(app尚未在Android Play商店中).我有以下逻辑来在MainActivity中获得深层链接.
GoogleApiClient mGoogleApiClient = new GoogleApiClient.Builder(this)
.enableAutoManage(this, null)
.addApi(AppInvite.API)
.build();
// Check if this app was launched from a deep link. Setting autoLaunchDeepLink to true
// would automatically launch the deep link if one is found.
boolean autoLaunchDeepLink = false;
AppInvite.AppInviteApi.getInvitation(mGoogleApiClient, this, autoLaunchDeepLink)
.setResultCallback(
new ResultCallback<AppInviteInvitationResult>() {
@Override
public void onResult(@NonNull AppInviteInvitationResult result) {
if (result.getStatus().isSuccess()) {
// Extract deep link from Intent
Intent intent = result.getInvitationIntent();
String deepLink = AppInviteReferral.getDeepLink(intent);
Toast.makeText(getApplicationContext(), deepLink, Toast.LENGTH_LONG).show();
// Handle the deep link. For example, open the linked
// content, or apply promotional credit to the user's
// account.
// ...
} else {
Log.d(TAG, "getInvitation: no deep link found.");
}
}
});
Run Code Online (Sandbox Code Playgroud)
我使用Firebase控制台构建了一些动态链接,并在移动浏览器中打开.但它没有打开我的应用程序并且达到了字符串deepLink = AppInviteReferral.getDeepLink(intent);
相反,它是在移动浏览器本身打开URL.
如何在使用firebase动态链接时打开应用程序并处理活动中的深层链接?
我有清单文件中的意图过滤器.
<activity android:name="MainActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:host="example.com" android:scheme="http"/>
<data android:host="example.com" android:scheme="https"/>
</intent-filter>
</activity>
Run Code Online (Sandbox Code Playgroud)
小智 11
Action View 和 Action Main 都属于不同的 Intent 类别。因此,您需要将它们放在不同的块中,如下所示:
<activity android:name=".DynamicLinkActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<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:host="example.com"
android:scheme="http" />
<data
android:host="example.com"
android:scheme="https" />
</intent-filter>
</activity>
Run Code Online (Sandbox Code Playgroud)
或者,您也可以在intent-filter中提供数据,如"常规"深层链接文档中所述(https://developer.android.com/training/app-indexing/deep-linking.html)
然后,intent过滤器将如下所示:
<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="https://XXYYZZ42.app.goo.gl/" // <- Replace with your deep link from the console
android:scheme="https"/>
</intent-filter>
Run Code Online (Sandbox Code Playgroud)
编辑:添加图片,以显示在哪里可以找到此链接
归档时间: |
|
查看次数: |
10853 次 |
最近记录: |