Facebook deferred deep linking not working when ad preview is clicked - android

<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();
}

Related

Tracking referrals for app install using firebase

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>

Unable to fetch referral code after install android app from app store

In my application have a referral program.I want when a customer share app link, that link redirect to playstore and after install app referral code retrieve from playstore. I already do that link but I don't understand how can i receive that referral code after install.
public static void shareMyApp(Context context) {
String link = "https://play.google.com/store/apps/details?id="+context.getPackageName();
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("text/*");
sharingIntent.putExtra(Intent.EXTRA_TEXT, link);
context.startActivity(Intent.createChooser(sharingIntent, "Share Via"));
}
For that, you have to use below the library
implementation 'com.android.installreferrer:installreferrer:1.0'
https://developer.android.com/google/play/installreferrer/library
https://developer.android.com/training/app-links/deep-linking.html
Thanks, it may help you
Create a link with referral code and send to others friends and users...
String link = http://yourdomain.com/testrefer.php?refercode=ABCD // http or https
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
sharingIntent.putExtra(Intent.EXTRA_TEXT, link);
context.startActivity(Intent.createChooser(sharingIntent, "Share Via"));
and in testrefer file to create app store link and append refercode and then redirect to play store using below link and then you can get referral code.
https://play.google.com/store/apps/details?id="+context.getPackageName()+"&referrer=ABCD
in Manifest file in your launching screen to write below code
<activity
android:name=".activity.SplActivity"
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="yourdomain.com"
android:pathPrefix="/testrefer.php"
android:scheme="https" /> <!-- https or http -->
</intent-filter>
</activity>
InstallRefererReciever is a file name that you have created BroadcastReceiver
<receiver
android:name=".common.InstallRefererReciever"
android:exported="true"
android:permission="android.permission.INSTALL_PACKAGES">
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER" />
</intent-filter>
</receiver>
Create BroascatReceiver and write below code :
public class InstallRefererReciever extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
if (intent != null) {
Bundle extras = intent.getExtras();
if (extras != null) {
String referral = extras.getString("referrer");
Logger.e("ReferCode --> ", referral);
if (referral != null) {
if (!referral.equals("utm_source=google-play&utm_medium=organic")) {
if (!referral.equals("com.android.chrome")) {
String referralCode = referral; // Store in sharedpreferences
}
}
}
}
}
}
}

Start an app within another app Android

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();
}
}

Android deep linking is not working

Android deep linking is not working
===================================
Android link:-notification://id=notificationid
1:-In manifest
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="id"
android:scheme="notification" />
</intent-filter>
2:-and coding side
#Override
protected void onResume() {
super.onResume();
Intent intent = getIntent();
String string=intent.getAction();
Uri data = intent.getData();
Log.d("hello","cgbdsuyfdkv");
}
but its not working please any body can help me !!!!!
you can simply modify your url
Android link:-notification://id=notificationid instead of
Android link:-notification://page?id=notificationid //page is host name
I tried a lot and find out this is working for me.
manifest code
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="page"
android:scheme="notification" />
</intent-filter>
2.java code #get your notification id here
Intent intent = getIntent();
String string = intent.getAction();
Uri data = intent.getData();
if (data != null) {
String path = data.getPath();
String path1 = data.getPath();
providerUrl = intent.getData().toString();
UrlQuerySanitizer sanitizer = new UrlQuerySanitizer();
sanitizer.setAllowUnregisteredParamaters(true);
sanitizer.parseUrl(providerUrl);
String id = sanitizer.getValue("id");
if (id != null)
Log.d("notification id", id);
}
Add onNewIntent() method to your Activity and then use intent object which is variable in OnNewintent() method , which has updated method.
onNewIntent() is meant as entry point for singleTop or singleTask activities which already run somewhere else in the stack and therefore can't call onCreate(). From activities lifecycle point of view it's therefore needed to call onPause() before onNewIntent(). I suggest you to rewrite your activity to not use these listeners inside of onNewIntent(). For example most of the time my onNewIntent() methods simply looks like this:
#Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
//use this intent object to get notificationid for second time
}
1st step:
<intent-filter>
<data android:scheme="your_uri_scheme" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
2nd step:
Uri data = this.getIntent().getData();
if (data != null && data.isHierarchical()) {
String uri = this.getIntent().getDataString();
Log.i("MyApp", "Deep link clicked " + uri);
}
I think you Intent Filter is incomplete
<!-- To open app using link -->
<intent-filter>
<action android:name="android.intent.action.VIEW"></action>
<category android:name="android.intent.category.DEFAULT"></category>
<category android:name="android.intent.category.BROWSABLE"></category>
<data android:scheme="http"
android:host="yourdomain.com"
android:pathPrefix="/someurlparam">
</data>
</intent-filter>

How to use intent for sharing gallery picture to application

I have added my application to the share icon on top in the gallery, but so far it only opens my application, but how do I send the picture URI and stuff to my application? I understand I have to use intent? Are there any guides around I can look at? The easy-share-action guide on google website isn't helping me much here.
Try this way:
<activity
android:name="yourActivity"
android:icon="#drawable/ic_launcher"
android:label="test">
<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.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
</intent-filter>
<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.SEND_MULTIPLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
</intent-filter>
</activity>
Handle the Incoming Content
void onCreate (Bundle savedInstanceState) {
...
// Get intent, action and MIME type
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
} else if (type.startsWith("image/")) {
handleSendImage(intent); // Handle single image being sent
}
} else if (Intent.ACTION_SEND_MULTIPLE.equals(action) && type != null) {
if (type.startsWith("image/")) {
handleSendMultipleImages(intent); // Handle multiple images being sent
}
} else {
// Handle other intents, such as being started from the home screen
}
...
}
void handleSendText(Intent intent) {
String sharedText = intent.getStringExtra(Intent.EXTRA_TEXT);
if (sharedText != null) {
// Update UI to reflect text being shared
}
}
void handleSendImage(Intent intent) {
Uri imageUri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);
if (imageUri != null) {
// Update UI to reflect image being shared
}
}
void handleSendMultipleImages(Intent intent) {
ArrayList<Uri> imageUris = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
if (imageUris != null) {
// Update UI to reflect multiple images being shared
}
}
For more information go to Receiving Simple Data from Other Apps and Sending Simple Data to Other Apps
To handle an image in your Activity you need to check if the intent has the image.
Intent intent = getIntent();
Bundle extras = intent.getExtras();
String action = intent.getAction();
if (Intent.ACTION_SEND.equals(action)) {
if (extras.containsKey(Intent.EXTRA_STREAM)) {
// Get resource path of the stream, which in this case will be the image
}
}
Furthermore you need to add to your manifest that you want to filter on these sharing image intents.
<activity android:name=".Theme"
android:label="YourImageActivity">
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
</intent-filter>
</activity>

Categories

Resources