Am trying to track referrals from user1 to user2 using firebase. Here is what u did.
From the person inviting am generating following link
https://play.google.com/store/apps/details?id=com.mindedges.freegiveaway.freegiveaway&invitedby=xyzuser
So the receiver receives the above link which was generated by following code:
private void sendNativeInvites(){
String email = UserUtils.getCurrentUser(this).getEmail();
String packageName = getPackageName();
String link = "https://play.google.com/store/apps/details?id="+packageName+"&invitedby=" + email;
DynamicLink dynamicLink = FirebaseDynamicLinks.getInstance().createDynamicLink()
.setLink(Uri.parse(link))
.setDomainUriPrefix("https://freegiveaway.page.link")
.setAndroidParameters(
new DynamicLink.AndroidParameters.Builder(getPackageName()).build())
.buildDynamicLink();
Uri dynamicLinkUri = dynamicLink.getUri();
doSendInvite(dynamicLinkUri);
}
When the receiver clicks the link he will go to playstore and I expect that the app will be installed and launched with the above deep link.
On the main activity of the app i have following code to fetched the referrer but I cant find it.
private void fetchReferrerIfPresent(){
Log.d(TAG, "fetchReferrerIfPresent");
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,"deepLink = " + deepLink); //Getting null
if (deepLink != null && deepLink.getBooleanQueryParameter("invitedby", false)) {
referrerEmail = deepLink.getQueryParameter("invitedby");
Log.d(TAG, "Found referrerEmail. referrerEmail = " + referrerEmail);
}else{
Log.d(TAG, "No referrer found");
}
}
}).addOnFailureListener(new OnFailureListener() {
#Override
public void onFailure(#NonNull Exception e) {
Log.e(TAG, "Exception while fetching referrerEmail", e);
}
});
}
In the manifest i have :
<activity
android:name="com.mindedges.freegiveaway.freegiveaway.LoginActivity"
android:label="#string/app_name"
android:noHistory="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<!--
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
-->
<data
android:host="freegiveaway.page.link"
android:scheme="https" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Related
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:screenOrientation="sensorLandscape">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<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" />
<!-- Accepts URIs that begin with "memoryc://cerebrotrial” -->
<data
android:host="cerebrotrial"
android:scheme="memoryc" />
</intent-filter>
</activity>
When I test my ad from the Ad Helper in Facebook, the deferred link is successfully transmitted. But when I click the ad preview from the Facebook app, the deferred deep link is null. I try to catch the deep-link with the below implementations. I first try to get the deep link from the AppLinkData, then from the most basic getIntent() implementation and finally by the bolts.Applinks. The ApplinkData is null, the intent does not return anything and the targetUrl is null.
// Suggested Facebook implementation
FacebookSdk.setAutoInitEnabled(true);
FacebookSdk.fullyInitialize();
AppLinkData.fetchDeferredAppLinkData(this,
new AppLinkData.CompletionHandler() {
#Override
public void onDeferredAppLinkDataFetched(AppLinkData appLinkData) {
// Process app link data
if (appLinkData != null) {
ConfigAPI.setRefererURL(appLinkData.getTargetUri().toString());
JsonObject jsonParams = ConfigAPI.getPayLoad();
new CallAPI(jsonParams).execute();
}
}
}
);
//persist deep link data
Intent intent = getIntent();
Uri data = intent.getData();
if (data != null) {
Log.i("DEEP LINK", data.toString());
ConfigAPI.setRefererURL(data.toString());
JsonObject jsonParams = ConfigAPI.getPayLoad();
new CallAPI(jsonParams).execute();
}
// using the bolts.Applinks
Uri targetUrl = AppLinks.getTargetUrlFromInboundIntent(this, getIntent());
if (targetUrl != null) {
ConfigAPI.setRefererURL(targetUrl.toString());
JsonObject jsonParams = ConfigAPI.getPayLoad();
new CallAPI(jsonParams).execute();
}
I'm trying to build an app using stackexchange api and user will able to use app after authenticating them self with stackoverflow.com . But problem here i am getting is after completing authentication when app is reopened and i am looking for data in intent in onResume() so it is null but is should consist a callback url with access token. when i open url which i passed to intent for authentication into browser so with callback url access_token is associated but in app i am getting null!
MainAcitivity
public class MainActivity extends AppCompatActivity {
private static final String TAG = "MainActivity";
Uri uri = new Uri.Builder()
.scheme("https")
.authority("stackoverflow.com")
.appendPath("oauth").appendPath("dialog")
.appendQueryParameter("client_id", "14910")
.appendQueryParameter("scope", "read_inbox")
.appendQueryParameter("redirect_uri", "https://stackoverflow.com/oauth/login_success")
.build();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.d(TAG, "onCreate: uri : " + uri);
Intent intent = new Intent(
Intent.ACTION_VIEW,
uri);
startActivity(intent);
}
#Override
protected void onResume() {
super.onResume();
Log.d(TAG, "onResume: intent: " + getIntent());
Log.d(TAG, "onResume: uri: " + getIntent().getData());
Uri uri = getIntent().getData();
if (uri != null && uri.toString().startsWith("stackoverflow.com/oauth/login_success")) {
String code = uri.getQueryParameter("code");
if (code != null) {
Log.d(TAG, "onResume: code:" + code);
} else if (uri.getQueryParameter("error") != null) {
Log.d(TAG, "onResume: error" + uri.getQueryParameter("error"));
}
}else{
Log.d(TAG, "onResume: else");
}
}
}
Manifest
...
<activity android:name=".MainActivity"
android:launchMode="singleTop">
<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="stackoverflow.com"
android:pathPrefix="/oauth/login_success"
android:scheme="https" />
</intent-filter>
</activity>
...
StackExchange api setup for project
[project image]: https://github.com/chetan882777/git-training/blob/master/Screenshot_2019-04-14%20Editing%20project.png "
If i show here uri passed into intent:
https://stackoverflow.com/oauth/dialog?client_id=14910&scope=read_inbox&redirect_uri=https%3A%2F%2Fstackoverflow.com%2Foauth%2Flogin_success
and after that response url i obtained after authentication:
https://stackoverflow.com/oauth/login_success#access_token=nwIxeGi73Bf0rA9Ij4iwcQ))&expires=86400
How should be my android manifest file if I want to show my app in the chooser apps if someone clicks the dynamic link? The URL prefix is like -
https://testapp.page.link. At that stage if someone clicks the link then it first opens the browser then it redirects to my app. But I want to show my app in the chooser app list. At this time my manifest file is like follows-
<activity android:name=".extraActivities.DynamicLinkActivity">
<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="test.com"
android:pathPattern="https://testapp.page.link*"
android:scheme="https"
/>
</intent-filter>
</activity>
We need to write intent-filter in the manifest file as follows-
<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="testapp.com"
android:pathPattern=".*"
android:scheme="https" />
<data
android:host="testapp.page.link"
android:scheme="https"
android:pathPattern=".*"/>
</intent-filter>
Where "testapp.page.link" is the actually the URL prefixes shown at the top left corner of Firebase dynamic link console. And "testapp.com" is the first part of any link. Eg: https://testapp.com/user_profile?id="Zsdsdjwenncsdmsd". From this link, we can extract the user Id as "Zsdsdjwenncsdmsd" at the receiving end of the dynamic link. A complete example is shown below-
If anyone clicks share button this will create the dynamic link-
shareBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
shareProgressBar.setVisibility(View.VISIBLE);
Task<ShortDynamicLink> shortDynamicLinkTask = buildDeepLink(getString(R.string.grp_post_link)+postsModel.getPostId()+"&groupKey="+postsModel.getGroupKey()+"&groupName="+ dataSnapshot.getValue(String.class));
shortDynamicLinkTask.addOnCompleteListener(new OnCompleteListener<ShortDynamicLink>() {
#Override
public void onComplete(#NonNull Task<ShortDynamicLink> task) {
grpPostsViewHolder.shareProgressBar.setVisibility(View.GONE);
if(task.isSuccessful()){
Uri uri = task.getResult().getShortLink();
share(dataSnapshot.getValue(String.class), uri.toString());
}else {
Toast.makeText(context, "Can't create link", Toast.LENGTH_SHORT).show();
}
}
});
shortDynamicLinkTask.addOnFailureListener(new OnFailureListener() {
#Override
public void onFailure(#NonNull Exception e) {
shareProgressBar.setVisibility(View.GONE);
}
});
The dynamic link creator function and share function-
/*-----------------------------------------------------------------------------*/
private Task<ShortDynamicLink> buildDeepLink(String deepLink) {
String uriPrefix = getString(R.string.dynamic_links_uri_prefix);
return FirebaseDynamicLinks.getInstance().createDynamicLink()
.setLink(Uri.parse(deepLink))
.setDomainUriPrefix(uriPrefix)
.setNavigationInfoParameters(new DynamicLink.NavigationInfoParameters.Builder()
.build())
.setAndroidParameters(new DynamicLink.AndroidParameters.Builder()
.setMinimumVersion(3)
.build())
.buildShortDynamicLink();
}
/*-----------------------------------------------------------------------------*/
private void share(String name, String deepLink) {
String message = "Find "+name+" on SelfieLe - link: "+deepLink;
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, message);
startActivity(intent);
}
/*---------------------------------------------------------------------------------*/
The String resources are-
R.string.grp_post_link, and R.string.dynamic_links_uri_prefix:
<string name="user_profile_link">https://testapp.com/user_profile?id=</string>
<string name="dynamic_links_uri_prefix">https://testapp.page.link</string>
At receiving end we can extract postId, groupKey etc as follows
FirebaseDynamicLinks.getInstance().getDynamicLink(getIntent()).addOnSuccessListener(this, new OnSuccessListener<PendingDynamicLinkData>() {
#Override
public void onSuccess(PendingDynamicLinkData pendingDynamicLinkData) {
if (pendingDynamicLinkData != null) {
deepLink = pendingDynamicLinkData.getLink();
}
if (deepLink != null) {
getGrpPost(deepLink.getQueryParameter("id"), deepLink.getQueryParameter("groupKey"), deepLink.getQueryParameter("groupName"));
}else {
Toast.makeText(DynamicLinkActivity.this, "Can't find link", Toast.LENGTH_SHORT).show();
}
}
}).addOnFailureListener(this, new OnFailureListener() {
#Override
public void onFailure(#NonNull Exception e) {
Toast.makeText(DynamicLinkActivity.this, "Can't find link", Toast.LENGTH_SHORT).show();
}
});
The getGroupPost(); is as follows
private void getGrpPost(String id, String groupKey, final String groupName) {
//Do what you want
}
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).
My question is how to start app A within app B that appears app A is within app B through deep linking?
In the first picture below, the Debug app appears as a separate app from Slack (new code, Firebase deep linking). In the 2nd picture, the Debug app appears to be within the Slack app (old code, Android deep linking). I want to use Firebase deep linking and show the Debug app within other apps (Slack, Gmail etc).
Can anyone please go through my code below and let me know how I can achieve this?
Old code, Android deep linking:
AndroidManifest
<activity
android:name=".activity.SplashScreenActivity"
android:screenOrientation="portrait"
android:theme="#style/SplashTheme">
<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" />
<!-- Accepts URIs that begin with "abc://flights” -->
<data
android:host="sales"
android:scheme="abc" />
<data
android:host="deals"
android:scheme="abc" />
</intent-filter>
</activity>
Activity:
Intent intent = new Intent(SplashScreenActivity.this, BottomNavBarActivity.class);
//Deep Linking Content
Uri deepLinkData = getIntent().getData();
if (deepLinkData != null) {
intent.putExtra(EXTRA_DEEP_LINK, deepLinkData.getHost());
}
startActivity(intent);
overridePendingTransition(R.anim.splash_fade_in, R.anim.splash_fade_out);
finish();
New Code, Firebase deep linking:
AndroidManifest:
<activity
android:name=".activity.SplashScreenActivity"
android:screenOrientation="portrait"
android:theme="#style/SplashTheme">
<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="abc.app.goo.gl"
android:scheme="http"/>
<data
android:host="abc.app.goo.gl"
android:scheme="https"/>
</intent-filter>
</activity>
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) {
// Start the activity through intent, same as before.
}
}
})
.addOnFailureListener(this, new OnFailureListener() {
#Override
public void onFailure(#NonNull Exception e) {
Log.v(TAG, "Firebase deep link failure");
}
});
Its dependent on the app which sends the intent, for example whether they pass FLAG_ACTIVITY_NEW_TASK or not. I suspect the difference here is how Slack is handling the links - they may treat web URLs differently than other format ones (your old links have non-standard schemes).
Create a method openApp(), and call it accorrding to your need.
public void openAnApp()
{
Boolean flag=false;
try{
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
final PackageManager packageManager = getActivity().getPackageManager();
Intent intent1 = new Intent(Intent.ACTION_MAIN, null);
intent1.addCategory(Intent.CATEGORY_LAUNCHER);
List<ResolveInfo> resInfos = packageManager.queryIntentActivities(intent1, 0);
ActivityInfo activity = null;
//getting package names and adding them to the hashset
for(ResolveInfo resolveInfo : resInfos) {
System.out.println("apap="+resolveInfo.activityInfo.packageName);
if(resolveInfo.activityInfo.packageName.equals("your.app.packagename"))
{
flag = true;
activity = resolveInfo.activityInfo;
break;
}
}
if (flag) {
// final ActivityInfo activity = app.activityInfo;
final ComponentName name = new ComponentName(activity.applicationInfo.packageName,activity.name);
intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.setComponent(name);
getActivity().startActivity(intent);
//startActivity(Intent.createChooser(intent , "Send image using.."));
} else {
Uri uri=Uri.parse("market://details?id=your.app.packagename");
Intent goToMarket=new Intent(Intent.ACTION_VIEW,uri);
try{
startActivity(goToMarket);
}catch(ActivityNotFoundException e){
Toast.makeText(getActivity(),"Couldn't launch the market",Toast.LENGTH_SHORT).show();
}
}
} catch (Exception e) {
Toast.makeText(getActivity(), "Something went wrong", Toast.LENGTH_LONG).show();
e.printStackTrace();
}
}