Skip to content

Commit

Permalink
If the current app can already handle the deep link, default to using it
Browse files Browse the repository at this point in the history
  • Loading branch information
catacom committed Feb 8, 2017
1 parent 0a353f4 commit 58ff775
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions android-sdk-ui/src/com/appboy/push/AppboyNotificationUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ResolveInfo;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
Expand Down Expand Up @@ -37,6 +38,7 @@
import org.json.JSONObject;

import java.util.Iterator;
import java.util.List;

public class AppboyNotificationUtils {
private static final String TAG = String.format("%s.%s", Constants.APPBOY_LOG_TAG_PREFIX, AppboyNotificationUtils.class.getName());
Expand Down Expand Up @@ -119,6 +121,18 @@ public static void routeUserWithNotificationOpenedIntent(Context context, Intent
Log.d(TAG, String.format("Found a deep link %s.", deepLink));
Intent uriIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(deepLink))
.putExtras(extras);

// If the current app can already handle the deep link, default to using it
List<ResolveInfo> resolveInfos = context.getPackageManager().queryIntentActivities(uriIntent, 0);
if (resolveInfos.size() > 1) {
for (ResolveInfo resolveInfo : resolveInfos) {
if (resolveInfo.activityInfo.packageName.equals(context.getPackageName())) {
uriIntent.setPackage(resolveInfo.activityInfo.packageName);
break;
}
}
}

TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
stackBuilder.addNextIntent(startActivityIntent);
stackBuilder.addNextIntent(uriIntent);
Expand Down

0 comments on commit 58ff775

Please sign in to comment.