我正在尝试在我的应用程序中配置 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 文件是这样的:
深度链接演示
<!-- 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 以及它将指向哪里。
此外,当我尝试在设备中安装此应用程序时,它没有安装。我不知道它没有安装的原因。
谢谢