我正在尝试在我的应用中配置firebase动态链接,但面临的问题很少。
我做了以下事情: 1.完成Firebase控制台的设置。 2.我在清单中的代码:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.manpsing.deeplinkdemo">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<!-- [START link_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="https"/>
</intent-filter>
<!-- [END link_intent_filter] -->
</activity>
</application>
</manifest>
主要活动中的代码:
公共类MainActivity扩展AppCompatActivity实现了GoogleApiClient.OnConnectionFailedListener {
private static final String TAG = "MainActivity";
private static final String DEEP_LINK_URL = "https://example.com/deeplinks";
// [START define_variables]
private GoogleApiClient mGoogleApiClient;
// [END define_variables]
// [START on_create]
@Override
protected void onCreate(Bundle savedInstanceState) {
// [START_EXCLUDE]
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Validate that the developer has set the app code.
validateAppCode();
// Create a deep link and display it in the UI
final Uri deepLink = buildDeepLink(Uri.parse(DEEP_LINK_URL), 0, false);
((TextView) findViewById(R.id.link_view_send)).setText(deepLink.toString());
// Share button click listener
findViewById(R.id.button_share).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
shareDeepLink(deepLink.toString());
}
});
// [END_EXCLUDE]
// [START build_api_client]
// Build GoogleApiClient with AppInvite API for receiving deep links
mGoogleApiClient = new GoogleApiClient.Builder(this)
.enableAutoManage(this, this)
.addApi(AppInvite.API)
.build();
// [END build_api_client]
// [START get_deep_link]
// 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(AppInviteInvitationResult result) {
if (result.getStatus().isSuccess()) {
// Extract deep link from Intent
Intent intent = result.getInvitationIntent();
String deepLink = AppInviteReferral.getDeepLink(intent);
// Handle the deep link. For example, open the linked
// content, or apply promotional credit to the user's
// account.
// [START_EXCLUDE]
// Display deep link in the UI
((TextView) findViewById(R.id.link_view_receive)).setText(deepLink);
// [END_EXCLUDE]
} else {
Log.d(TAG, "getInvitation: no deep link found.");
}
}
});
// [END get_deep_link]
}
我的strings.xml文件如下:
DeeplinkDemo
<!--
Your app code, see:
https://firebase.google.com/docs/dynamic-links/android
-->
<string name="app_code">pgm3j</string>
<string name="share">Share</string>
<string name="title_receive">Receive</string>
<string name="title_send">Send</string>
<string name="msg_no_deep_link">No deep link received.</string>
我想我还没有创建动态链接。请帮我怎么创建一个。还让我知道如何使用这个动态链接,即我需要打开的URL以及它指向的位置。
此外,当我尝试在设备中安装此应用时,它尚未安装。我不知道它未安装的原因。
由于
答案 0 :(得分:0)
处理动态链接有两个位:
1)处理常规深层链接
这意味着让您的应用处理网址。您已为example.com
添加了一个意图过滤器,该过滤器方向正确但您需要将其替换为您的域名。如果您没有,可以使用Firebase项目附带的[yourproject] .firebaseapp.com!
2)解析收到的网址
这是您的AppInviteApi
代码正在执行的操作,因此您在这里很好 - 解析从打开的URL生成的Intent,并提取深层链接。对于生产应用程序,相同的代码也将检索通过Play商店传递的数据,因此即使用户必须安装应用程序,该链接仍然有效。
最后,生成链接的最简单方法是使用Firebase Console的动态链接部分。