I am implementing a shopping app.In that when a product is shared it should send a dynamic link so that when a person clicks it , opens in app only.Finally i achieved this feature.But when i am opening app from a shared dynamic link i am getting home page rather than product page.I need help regarding getting specific product page rather opening home page of shopping. Here i am including code. AndroidManifest.xml
<activity android:name=".Postdetails">
<meta-data android:name="android.support.PARENT_ACTIVITY" android:value="MainActivity" />
<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="postdetailsnew.com" android:scheme="https"
android:pathPattern=".*"/>
</intent-filter>
</activity>
PostDetails.java Here PostDetails page is the single product design page or activity .In this i wrote following code.
sharebutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
s="https://app_code.app.goo.gl/?link="+ProductLinkInBrowser+"&apn=com.example.maneesh.shop";
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, s);
sendIntent.setType("text/plain");
startActivity(sendIntent);
}
}
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();
FirebaseAppInvite invite=FirebaseAppInvite.getInvitation(pendingDynamicLinkData);
if(invite!=null){
String invitationId=invite.getInvitationId();
}
}
}
})
.addOnFailureListener(this, new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Log.w("Heyy", "getDynamicLink:onFailure", e);
}
});
So here finally app main page is opened with dynamic link but not the specific product page which is shared.Please guide me to achieve this.
You need to parse the URL in the dynamic link, and fire an intent to send the user to the right part of your app. Generally you'll have the Dynamic Links listener set up in your main activity, and will route from there to any specific needs.
The
deepLink
variable in your code will be the URL your passed in the dynamic link, likehttp://yourshop.com/product/12345
. You could calldeepLink.getPath()
which would return you product/12345, and then fire and intent for that, e.g: