Skip to content

Commit 1a5ebe5

Browse files
author
sagi
committed
added deeplink activity
1 parent 17144cd commit 1a5ebe5

File tree

3 files changed

+57
-3
lines changed

3 files changed

+57
-3
lines changed

Android/DeeplinkActivity.java

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package com.trophit;
2+
3+
import com.unity3d.player.UnityPlayerActivity;
4+
import android.app.Activity;
5+
import android.content.Intent;
6+
import android.os.Bundle;
7+
import android.util.Log;
8+
import android.view.Window;
9+
10+
11+
public class DeeplinkActivity extends Activity {
12+
13+
@Override
14+
protected void onCreate(Bundle savedInstanceState) {
15+
super.onCreate(savedInstanceState);
16+
Intent intent = getIntent();
17+
Log.d(getClass().getName(), "onCreate " + intent.getAction() + " " + intent.getDataString());
18+
requestWindowFeature(Window.FEATURE_NO_TITLE);
19+
20+
Class<?> cls = getMainActivityClass();
21+
if (cls != null) {
22+
Intent newIntent = new Intent(this, cls);
23+
this.startActivity(newIntent);
24+
onDeeplink(intent);
25+
}
26+
finish();
27+
}
28+
29+
protected void onDeeplink(Intent intent) {
30+
if (Intent.ACTION_VIEW.equals(intent.getAction())) {
31+
String deeplink = intent.getDataString();
32+
Log.d(getClass().getName(), "onDeeplink " + deeplink);
33+
if (deeplink != null)
34+
com.unity3d.player.UnityPlayer.UnitySendMessage(gameObject, deeplinkMethod, deeplink);
35+
}
36+
}
37+
38+
private Class<?> getMainActivityClass() {
39+
String packageName = this.getPackageName();
40+
Intent launchIntent = this.getPackageManager().getLaunchIntentForPackage(packageName);
41+
try {
42+
return Class.forName(launchIntent.getComponent().getClassName());
43+
} catch (Exception e) {
44+
Log.e(getClass().getName(), "getMainActivityClass: Unable to find Main Activity Class");
45+
return null;
46+
}
47+
}
48+
49+
protected static final String gameObject = "UnityDeeplinks";
50+
protected static final String deeplinkMethod = "onDeeplink";
51+
}

Android/MyUnityPlayerActivity.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ protected void onDeeplink(Intent intent) {
2828
String deeplink = intent.getDataString();
2929
Log.d(getClass().getName(), "onDeeplink " + deeplink);
3030
if (deeplink != null)
31-
com.unity3d.player.UnityPlayer.UnitySendMessage("UnityDeeplinks", "onDeeplink", deeplink);
31+
com.unity3d.player.UnityPlayer.UnitySendMessage(gameObject, deeplinkMethod, deeplink);
3232
}
3333
}
34-
}
34+
35+
protected static final String gameObject = "UnityDeeplinks";
36+
protected static final String deeplinkMethod = "onDeeplink";
37+
}

Android/build_jar.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export ANDROID_SDK_ROOT
88

99
BOOTCLASSPATH=/Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home/jre/lib
1010
export BOOTCLASSPATH
11-
CLASSPATH=../AF-Android-SDK.jar:$UNITY_LIBS:$ANDROID_SDK_ROOT/platforms/android-23/android.jar
11+
CLASSPATH=$UNITY_LIBS:$ANDROID_SDK_ROOT/platforms/android-23/android.jar
1212
export CLASSPATH
1313

1414
echo "Compiling ..."

0 commit comments

Comments
 (0)