android firebase dynamic link PendingDynamicLinkData is null direct through app - android

Problem: Why is "Short dynamic links" created programatically wont open/launch the app directly?
I want to launch app directly when user clicks the dynamic url created dynamically by android app.
When clicking dynamic short link created dynamically by android app the following things happen,
1.Option show two options one is through chrome other is through app
2.if i choose chrome option, browser opens, shows a loading dialog box and launch app with PendingDynamicLinkData data
3.but if i choose app option, app lauches app but PendingDynamicLinkData is lost or null.
Any Help would be great. my manifest setting is below
<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="myapp.page.link" android:scheme="http"/>
<data android:host="myapp.page.link" android:scheme="https"/>
</intent-filter>

You should handle your PendingDynamicLinkData in activity to override onCreate and onNewIntent. Like this:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = getIntent();
if (intent != null) {
handleDeepLink(intent);
}
}
#Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
if (intent != null) {
handleDeepLink(intent);
}
}
private void handleDeepLink(Intent intent) {
FirebaseDynamicLinks.getInstance().getDynamicLink(intent).addOnSuccessListener(pendingDynamicLinkData -> {
if (pendingDynamicLinkData != null) {
Uri deepLink = pendingDynamicLinkData.getLink();
if (deepLink != null) {
// todo .....
}
}
});
}

I don't know the correct solution but I have found a trick that works.
First make sure that you have added the following intent filter to the activity that is supposed to handle the dynamic link:
<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="example.com"
android:scheme="http" />
<data
android:host="example.com"
android:scheme="https" />
</intent-filter>
Source
Then in your activity, use the following code to get the link:
String link=null;
if (getIntent().getData()!=null){
link=getIntent().getData().toString();
}

In the manifest, add the following intent filter to the activity that will handle the url:
override OnStart method of the target Activity:
public override fun onStart() {
super.onStart()
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();
}
// ...
}
})
.addOnFailureListener(this, new OnFailureListener() {
#Override
public void onFailure(#NonNull Exception e) {
Log.w(TAG, "getDynamicLink:onFailure", e);
}
});
The complete guide here.
For some reason, i couldn't make it work in the same activity that as action MAIN.

Related

how to implement Facebook sharing and then deep link that post using deep link(open my app) in android App?

I want to implement deep linking for facebook app post.
Firstly I want to share my App content on Facebook Post and when user tap on the post then if User already has the app installed then open app otherwise It will open app link.
I follow https://developers.facebook.com/docs/applinks/android and https://developers.facebook.com/docs/sharing/android#linkshare but It's not working
how to share this data using LinkShare on facebook
target_url: "https://developers.facebook.com/android"
extras:
fb_app_id: [YOUR_FACEBOOK_APP_ID]
fb_access_token: "[ACCESS_TOKEN]"
fb_expires_in: 3600
To implement deep linking and sharing together, need to implement this feature using branch.io
Add dependency :
compile 'com.google.android.gms:play-services-appindexing:9.+'
Add this code in the manifest file inside Launcher Activity
<!-- Branch URI Scheme -->
<intent-filter>
<data android:scheme="androidexample" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
<!-- Branch App Links (optional) -->
<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:scheme="https" android:host="example.app.link" />
<data android:scheme="https" android:host="example-alternate.app.link" />
</intent-filter>
Add this code to your Launcher Activity, You will get your link and data in this method
#Override
public void onStart() {
super.onStart();
// Branch init
Branch.getInstance().initSession(new Branch.BranchReferralInitListener() {
#Override
public void onInitFinished(JSONObject referringParams, BranchError error) {
if (error == null) {
Log.i("BRANCH SDK", referringParams.toString());
// Retrieve deeplink keys from 'referringParams' and evaluate the values to determine where to route the user
// Check '+clicked_branch_link' before deciding whether to use your Branch routing logic
} else {
Log.i("BRANCH SDK", error.getMessage());
}
}
}, this.getIntent().getData(), this);
}
Add this code in MyApplication class
// Branch logging for debugging
Branch.enableLogging();
// Branch object initialization
Branch.getAutoInstance(this);
You can create deep link using this code
LinkProperties lp = new LinkProperties()
.setChannel("facebook")
.setFeature("sharing")
.setCampaign("content 123 launch")
.setStage("new user")
.addControlParameter("$desktop_url", "http://example.com/home")
.addControlParameter("custom", "data")
.addControlParameter("custom_random",
Long.toString(Calendar.getInstance().getTimeInMillis()));
buo.generateShortUrl(this, lp, new
Branch.BranchLinkCreateListener() {
#Override
public void onLinkCreate(String url, BranchError error) {
if (error == null) {
Log.i("BRANCH SDK", "got my Branch link to share: " + url);
}
}
});
refer this for Android
refer this for ios

Why I am unable to get query parameters from Firebase deep link url in Android?

I am trying to get query params from this
short dynamic link : https://easyloans.page.link/test
Long Dynamic Link : https://easyloans.page.link/?link=https://www.availfinance.in&apn=com.avail.easyloans.android&utm_campaign=Test_Campaign_Name&utm_medium=Test_Medium&utm_source=Test_Source
Manifest :
<activity android:name=".Activites.DynamicLink">
<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="easyloans.page.link"
android:scheme="http"
android:pathPrefix="/"
android:pathPattern=".*"/>
<data
android:host="easyloans.page.link"
android:scheme="https"
android:pathPrefix="/"
android:pathPattern=".*"/>
</intent-filter>
</activity>
In Android Activity:
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.d(TAG, "source : " + pendingDynamicLinkData.getLink().getQueryParameter("utm_source"));
}
Log.d(TAG, "link " + deepLink);
}
})
.addOnFailureListener(this, new OnFailureListener() {
#Override
public void onFailure(#NonNull Exception e) {
Log.d(TAG, "getDynamicLink:onFailure", e);
}
});
Output which i am receiving is :
link https://www.availfinance.in
and source : null (I am expecting Test_Source in this)
The getLink() method returns the link parameter you set on the long FDL, which in your example link was just what was returned: link=https://www.availfinance.in.
The UTM parameters are passed automatically to Google Analytics for Firebase.
pendingDynamicLinkData.getLink().getQueryParameter("foo") will return a value only if it is on the URL contained within the link parameter, e.g. if your link was link=https://www.availfinance.in/?foo=bar (with appropriate URL encoding).

flutter how to open txt file with open with dialog to specific page?

I'm new on flutter and never used intent filter. so far I have everything working in my app. but I'm stuck in importing the file to app by open with dialog. I need the user when it click on the file it will go to the page and display the information in the file. I'm using ImportFile plugin and it work fine but it make it harder for the users to put the file they receive.
my app is list it in the open with dialog but when i click it, it just open the app I want it to open the app and view the text in the view text page not the homepage
AndroidManifest.xml
<
intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
<data android:pathPattern="*.*\\.txt" />
</intent-filter>
MainActivity.java
Intent intent = getIntent();
String action = intent.getAction();
String type = intent.getType();
if (Intent.ACTION_SEND.equals(action) && type != null) {
if ("text/plain".equals(type)) {
handleSendText(intent); // Handle text being sent
}
}
new MethodChannel(getFlutterView(), "app.channel.shared.data").setMethodCallHandler(new MethodChannel.MethodCallHandler() {
#Override
public void onMethodCall(MethodCall methodCall, MethodChannel.Result result) {
if (methodCall.method.contentEquals("getSharedText")) {
result.success(sharedText);
sharedText = null;
}
}
});
}
void handleSendText(Intent intent) {
sharedText = intent.getStringExtra(Intent.EXTRA_TEXT);
}
Thank you in advance
FlutterView has a setInitialRoute method you can use to specify a non-default route on launch.

How to push an ingested deep link back to a web browser on Android

I'm currently having trouble where I am ingesting a deep link in my application, but after further review of the URL, I want to push the URL back to the web browser to display since my application does not provide the capability of using it. When I try to open the URL in a web browser, nothing happens since I have it defined to be a deep link. I tried sanitizing in the manifest with android:pathPrefix="/#!/foo", but the # character is not supported and causes the whole thing to not work.
AndroidManifest.xml
<activity
android:name=".activities.IntentForwardingActivity"
android:launchMode="singleTask"
>
<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="www.example.com"
android:scheme="https"
/>
</intent-filter>
</activity>
IntentForwardingActivity.java
#Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
handleIntent(intent);
}
private void handleIntent(Intent intent) {
String action = intent.getAction();
if (action != null && action.equals(Intent.ACTION_VIEW)) {
Uri data = intent.getData();
handleDeepLinking(data.toString());
}
}
private void handleDeepLinking(String url) {
Intent intent;
if (url.contains("/#!/foo")) {
intent = HomeActivity.newIntentForFoo(this, url);
} else {
intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
}
startActivity(intent);
finish();
}

how do i handle this string to open my app

i get this string in a browser redirect
intent://view?id=123#Intent;package=com.myapp;scheme=myapp;launchFlags=268435456;end;
how do i work with it ?
found in : http://fokkezb.nl/2013/09/20/url-schemes-for-ios-and-android-2/
You have your answer in the part 1 of the same article :
http://fokkezb.nl/2013/08/26/url-schemes-for-ios-and-android-1/
Your activity must have an intent filter matching the given intent
Here you have :
package=com.myapp;scheme=myapp
Your app package must be com.myapp and the url scheme is myapp://
So you must declare your activity like that :
<activity android:name=".MyActivity" >
<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:scheme="myapp" />
</intent-filter>
</activity>
Then your activity will be automatically opened by android.
Optionnaly you can work with the uri received from your code, for example in the onResume method (why onResume ? -> because it is always called after onNewIntent) :
#Override
protected void onResume() {
super.onResume();
Intent intent = getIntent();
if (intent != null && intent.getData() != null) {
Uri uri = intent.getData();
// do whatever you want with the uri given
}
}
If your activity uses onNewIntent, i recommend to use setIntent so that code above is always executed on last intent :
#Override
protected void onNewIntent(Intent intent) {
setIntent(intent);
}
Does this answers your question ?

Categories

Resources