Skip to content

Commit

Permalink
Using intent's action and data instead of only the extras
Browse files Browse the repository at this point in the history
  • Loading branch information
Jei committed Aug 20, 2018
1 parent fd1cfb9 commit 1dceeab
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 21 deletions.
Binary file modified android/libs/arm64-v8a/libti.deeply.so
Binary file not shown.
Binary file modified android/libs/armeabi-v7a/libti.deeply.so
Binary file not shown.
Binary file modified android/libs/x86/libti.deeply.so
Binary file not shown.
14 changes: 8 additions & 6 deletions android/src/ti/deeply/DeepLinkHandlerActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;

Expand Down Expand Up @@ -40,20 +41,21 @@ private void processIntent(Intent intent) {
try {
TiDeeplyModule module = TiDeeplyModule.getModule();
Context context = getApplicationContext();
String data = intent.getDataString();
Uri data = intent.getData();
String action = intent.getAction();
Bundle extras = intent.getExtras();

Intent launcherIntent = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName());
launcherIntent.addCategory(Intent.CATEGORY_LAUNCHER);
launcherIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

if (module.hasCallback() && KrollRuntime.getInstance().getRuntimeState() != KrollRuntime.State.DISPOSED) {
module.sendDeepLink(data, action, extras);
} else {
launcherIntent.putExtra(TiDeeplyModule.INTENT_DATA, data);
launcherIntent.putExtra(TiDeeplyModule.INTENT_ACTION, action);
launcherIntent.putExtra(TiDeeplyModule.INTENT_EXTRAS, extras);
launcherIntent.addCategory(Intent.CATEGORY_LAUNCHER);
launcherIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
launcherIntent.setData(data);
launcherIntent.setAction(action);
launcherIntent.putExtras(intent);
launcherIntent.putExtra(TiDeeplyModule.EXTRA_DEEPLY_FLAG, true);
}

startActivity(launcherIntent);
Expand Down
25 changes: 10 additions & 15 deletions android/src/ti/deeply/TiDeeplyModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.appcelerator.titanium.TiApplication;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;

import org.appcelerator.kroll.common.Log;
Expand All @@ -32,9 +33,7 @@ public class TiDeeplyModule extends KrollModule
private static final String LCAT = "ti.deeply.TiDeeplyModule";
private static final boolean DBG = TiConfig.LOGD;

public static final String INTENT_DATA = "tideeply.data";
public static final String INTENT_ACTION = "tideeply.action";
public static final String INTENT_EXTRAS = "tideeply.extras";
public static final String EXTRA_DEEPLY_FLAG = "tideeply.isDeepLink";

private static TiDeeplyModule module = null;

Expand All @@ -56,31 +55,27 @@ public static TiDeeplyModule getModule() {
public void parseBootIntent() {
try {
Intent intent = TiApplication.getAppRootOrCurrentActivity().getIntent();
String data = intent.getStringExtra(INTENT_DATA);
String action = intent.getStringExtra(INTENT_ACTION);
Bundle extras = intent.getBundleExtra(INTENT_EXTRAS);

if (data != null) {
sendDeepLink(data, action, extras);
intent.removeExtra(INTENT_DATA);
intent.removeExtra(INTENT_ACTION);
intent.removeExtra(INTENT_EXTRAS);
Boolean deeplyFlag = intent.getBooleanExtra(EXTRA_DEEPLY_FLAG, false);

if (deeplyFlag == true) {
intent.removeExtra(EXTRA_DEEPLY_FLAG);
sendDeepLink(intent.getData(), intent.getAction(), intent.getExtras());
} else {
Log.d(LCAT, "Empty data in Intent");
Log.d(LCAT, "Not started by a deep link.");
}
} catch (Exception ex) {
Log.e(LCAT, "parseBootIntent" + ex);
}
}

public void sendDeepLink(String data, String action, Bundle extras) {
public void sendDeepLink(Uri data, String action, Bundle extras) {
if (callback == null) {
Log.e(LCAT, "sendDeepLink invoked but no callback defined");
return;
}

HashMap<String, Object> e = new HashMap<String, Object>();
e.put("data", data); // to parse on reverse on JS side
e.put("data", data.toString()); // to parse on reverse on JS side
e.put("action", action);
e.put("extras", convertBundleToMap(extras));

Expand Down

0 comments on commit 1dceeab

Please sign in to comment.