我已经应用了firebase动态链接,当我点击它在浏览器中打开的链接时。在firebase控制台中我创建了一些动态链接,但是当我在应用程序中构建链接时,我没有明确指定URL但是动态链接域。问题是,在控制台中的所有已创建的链接中,我已指定要打开的应用程序,而不是浏览器。
主要活动代码:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = (Button) findViewById(R.id.button);
FirebaseDynamicLinks.getInstance().getDynamicLink(getIntent())
.addOnSuccessListener(this, new OnSuccessListener<PendingDynamicLinkData>() {
@Override
public void onSuccess(PendingDynamicLinkData data) {
if (data == null) {
Log.d("NULL DATA ", "getInvitation: no data");
return;
}
// Get the deep link
Uri deepLink = data.getLink();
String requestId2 = deepLink.getQueryParameter("extra1");
// Handle the deep link
// [START_EXCLUDE]
Log.d("DEEP LINK URL ", "deepLink:" + deepLink);
if (deepLink != null) {
if(requestId2 == "value") {
Intent intent = new Intent(getApplicationContext(), Main2Activity.class);
startActivity(intent);
}
}
// [END_EXCLUDE]
}
})
.addOnFailureListener(this, new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Log.w("onFailure: ", "getDynamicLink:onFailure", e);
}
});
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//Uri BASE_URI = Uri.parse("https://example.com");
Uri BASE_URI = Uri.parse("https://in.example.com");
Uri APP_URI = BASE_URI.buildUpon().
appendQueryParameter("extra1", "value").build();
String encodedUri = null;
try {
encodedUri = URLEncoder.encode(APP_URI.toString(), "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
String domain = "abcd.app.goo.gl";
DynamicLink.Builder builder = FirebaseDynamicLinks.getInstance()
.createDynamicLink()
.setDynamicLinkDomain(domain)
.setLink(APP_URI);
DynamicLink link = builder.buildDynamicLink();
Log.v("ENCODED URI: ", encodedUri);
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_EMAIL, "");
intent.putExtra(Intent.EXTRA_SUBJECT, "GET TICKETS" );
intent.putExtra(Intent.EXTRA_TEXT, "Click here : " + link.getUri().toString());
startActivity(Intent.createChooser(intent, "Send Email"));
}
});
}
Android Manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.firebasetest">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
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>
<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>
</activity>
<activity android:name=".Main2Activity">
</activity>
</application>
</manifest>
在此之前我手动构建深层链接而不添加参数,它工作正常。由于我必须添加参数,我使用了buildDynamicLink();