-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
11 changed files
with
188 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 10 additions & 7 deletions
17
Branch-SDK/src/androidTest/java/io/branch/referral/test/mock/MockRemoteInterface.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
Branch-SDK/src/main/java/io/branch/referral/DeferredAppLinkDataHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package io.branch.referral; | ||
|
||
import android.content.Context; | ||
import android.os.Bundle; | ||
import android.text.TextUtils; | ||
|
||
import java.lang.reflect.InvocationHandler; | ||
import java.lang.reflect.Method; | ||
import java.lang.reflect.Proxy; | ||
|
||
/** | ||
* Created by sojanpr on 5/19/16. | ||
* Class for handling deferred app links | ||
*/ | ||
class DeferredAppLinkDataHandler { | ||
private static final String NATIVE_URL_KEY = "com.facebook.platform.APPLINK_NATIVE_URL"; | ||
|
||
public static Boolean fetchDeferredAppLinkData(Context context, final AppLinkFetchEvents callback) { | ||
boolean isRequestSucceeded = true; | ||
try { | ||
// Init FB SDK | ||
Class<?> FacebookSdkClass = Class.forName("com.facebook.FacebookSdk"); | ||
Method initSdkMethod = FacebookSdkClass.getMethod("sdkInitialize", Context.class); | ||
initSdkMethod.invoke(null, context); | ||
|
||
final Class<?> AppLinkDataClass = Class.forName("com.facebook.applinks.AppLinkData"); | ||
Class<?> AppLinkDataCompletionHandlerClass = Class.forName("com.facebook.applinks.AppLinkData$CompletionHandler"); | ||
Method fetchDeferredAppLinkDataMethod = AppLinkDataClass.getMethod("fetchDeferredAppLinkData", Context.class, String.class, AppLinkDataCompletionHandlerClass); | ||
|
||
InvocationHandler ALDataCompletionHandler = new InvocationHandler() { | ||
@Override | ||
public Object invoke(Object proxy, Method method, Object[] args) throws Exception { | ||
if (method.getName().equals("onDeferredAppLinkDataFetched") && args[0] != null) { | ||
String appLinkUrl = null; | ||
Object appLinkDataClass = AppLinkDataClass.cast(args[0]); | ||
Method getArgumentBundleMethod = AppLinkDataClass.getMethod("getArgumentBundle"); | ||
Bundle appLinkDataBundle = Bundle.class.cast(getArgumentBundleMethod.invoke(appLinkDataClass)); | ||
|
||
if (appLinkDataBundle != null) { | ||
appLinkUrl = appLinkDataBundle.getString(NATIVE_URL_KEY); | ||
} | ||
|
||
if (callback != null) { | ||
callback.onAppLinkFetchFinished(appLinkUrl); | ||
} | ||
|
||
} else { | ||
if (callback != null) { | ||
callback.onAppLinkFetchFinished(null); | ||
} | ||
} | ||
return null; | ||
} | ||
}; | ||
|
||
Object completionListenerInterface = Proxy.newProxyInstance(AppLinkDataCompletionHandlerClass.getClassLoader() | ||
, new Class<?>[]{AppLinkDataCompletionHandlerClass} | ||
, ALDataCompletionHandler); | ||
|
||
String fbAppID = context.getString(context.getResources().getIdentifier("facebook_app_id", "string", context.getPackageName())); | ||
if (TextUtils.isEmpty(fbAppID)) { | ||
isRequestSucceeded = false; | ||
} else { | ||
fetchDeferredAppLinkDataMethod.invoke(null, context, fbAppID, completionListenerInterface); | ||
} | ||
|
||
} catch (Exception ex) { | ||
isRequestSucceeded = false; | ||
} | ||
return isRequestSucceeded; | ||
} | ||
|
||
public interface AppLinkFetchEvents { | ||
void onAppLinkFetchFinished(String nativeAppLinkUrl); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters