问题
Hello there I am new to Firebase Dynamic Links and learning it to my own, I have been following this tutorial to get through it.
My Code Creation method is:
private void createLink() {
String link = "https://play.google.com/store/apps/details?id=com.test.app&referrer="+"test1234" ;
FirebaseDynamicLinks.getInstance().createDynamicLink()
.setLink(Uri.parse(link))
.setDynamicLinkDomain("testxyz.page.link")
.setAndroidParameters(
new DynamicLink.AndroidParameters.Builder("com.test.app")
.setMinimumVersion(125)
.build())
.buildShortDynamicLink().addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Log.e("xyz", "error:::" + e.toString());
}
})
.addOnSuccessListener(new OnSuccessListener<ShortDynamicLink>() {
@Override
public void onSuccess(ShortDynamicLink shortDynamicLink) {
Log.e("xyz", "link:::" + shortDynamicLink.getShortLink());
}
});
}
It gives me the url like: https://testxyz.page.link/RhSKMYMnE2YHLbZk6 I copied and pasted it to my browser and it works fine, took me to the play store and showed my required app that I want to open with this link with app id: com.test.app
What I done for testing is to click on this url from my Android Phone that has the app installed with app id: com.test.app that it should be opened with the URL I clicked!
I am receiving the Link in my app with id: com.test.app with method:
private void check(){
FirebaseDynamicLinks.getInstance()
.getDynamicLink(getIntent())
.addOnSuccessListener(this, new OnSuccessListener<PendingDynamicLinkData>() {
@Override
public void onSuccess(PendingDynamicLinkData pendingDynamicLinkData) {
// Get deep link from result (may be null if no link is found)
Uri deepLink = null;
if (pendingDynamicLinkData != null) {
deepLink = pendingDynamicLinkData.getLink();
Log.e("deeplink","link:::"+deepLink);
Toast.makeText(IndexActivity.this, "link:::"+deepLink, Toast.LENGTH_SHORT).show();
}else{
Log.e("deeplink","link is null:::");
Toast.makeText(IndexActivity.this, "link is null:::", Toast.LENGTH_SHORT).show();
}
//
// If the user isn't signed in and the pending Dynamic Link is
// an invitation, sign in the user anonymously, and record the
// referrer's UID.
//
}
});
}
This method is being placed inside my main activity that comes after my Splash activity!
So the manifest has:
<activity
android:name=".MainActivity"
android:screenOrientation="portrait">
<intent-filter android:autoVerify="true">
<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://testxyz.page.link"
android:scheme="http"/>
<data
android:host="https://testxyz.page.link"
android:scheme="https"/>
</intent-filter>
</activity>
The Problem: When i clicked my Firebase generated Dynamic Link it works and takes me to the browser and opened the Google Play Store with my required app.
What I want is to open the app and get the dynamic link info for the referrer!
What I am doing wrong is that I have no idea because I am totaly new to Firebase Deep Linking.
Actually I want to create a link that I can send to the other user with my username and if the user clicks that link will open up the app if installed and if not installed take the user to the app store installs the app and get the deep link info for referrer
Any help or tutorial is heighly appreciated, thanks in advance!
回答1:
Set your android parameter as follow:
setAndroidParameters(new DynamicLink.AndroidParameters.Builder(BuildConfig.APPLICATION_ID)
.setMinimumVersion(1)
.build())
Your dynamic link is not able to open your app because you are not defining your package in Android parameter.
Be careful: The constructor of Firebase looks like adding package name as default, but it does not works.
public Builder() {
if (FirebaseApp.getInstance() == null) {
throw new IllegalStateException("FirebaseApp not initialized.");
} else {
this.zzf = new Bundle();
this.zzf.putString("apn", FirebaseApp.getInstance().getApplicationContext().getPackageName());
}
}
回答2:
My solution was non code related, I had to change my default browser. Google chrome was hijacking my dynamic link. I am using brave browser now and it opens my app directly.
来源:https://stackoverflow.com/questions/51222313/firebase-deep-link-opens-the-play-store-instead-of-app