diff --git a/CHANGELOG.md b/CHANGELOG.md index 73dab4e96..6dabea164 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +# 2018-05-22 - v5.1.2 + +#### Bugs Fixed + +* Properly handle different app support library versions. + # 2018-05-09 - v5.1.1 #### Bugs Fixed diff --git a/README.md b/README.md index 39c56a24a..386469d53 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ use your app, to talk to them at the right time, and in the right way. ##### [Release Notes](https://learn.apptentive.com/knowledge-base/android-sdk-release-notes/) -##### Binary releases are hosted for Maven [here](http://search.maven.org/#artifactdetails|com.apptentive|apptentive-android|5.1.1|aar) +##### Binary releases are hosted for Maven [here](http://search.maven.org/#artifactdetails|com.apptentive|apptentive-android|5.1.2|aar) #### Reporting Bugs diff --git a/apptentive/src/main/java/com/apptentive/android/sdk/ApptentiveViewActivity.java b/apptentive/src/main/java/com/apptentive/android/sdk/ApptentiveViewActivity.java index f3125c3e2..19d9adf1f 100644 --- a/apptentive/src/main/java/com/apptentive/android/sdk/ApptentiveViewActivity.java +++ b/apptentive/src/main/java/com/apptentive/android/sdk/ApptentiveViewActivity.java @@ -19,6 +19,7 @@ import android.os.Bundle; import android.support.v4.app.FragmentManager; import android.support.v4.content.ContextCompat; +import android.support.v4.content.IntentCompat; import android.support.v4.content.res.ResourcesCompat; import android.support.v4.view.ViewPager; import android.support.v7.app.ActionBar; @@ -358,22 +359,28 @@ private void addFragmentToAdapter(ApptentiveBaseFragment f, String title) { * activity, instead of desktop. * */ private void startLauncherActivityIfRoot() { - if (isTaskRoot()) { - PackageManager packageManager = getPackageManager(); - Intent intent = packageManager.getLaunchIntentForPackage(getPackageName()); + try { + if (isTaskRoot()) { + PackageManager packageManager = getPackageManager(); + Intent intent = packageManager.getLaunchIntentForPackage(getPackageName()); /* Make this work with Instant Apps. It is possible and even likely to create an Instant App that doesn't have the Main Activity included in its APK. In such cases, this Intent is null, and we can't do anything apart from exiting our Activity. */ - if (intent != null) { - ComponentName componentName = intent.getComponent(); - /** Backwards compatible method that will clear all activities in the stack. */ - Intent mainIntent = Intent.makeRestartActivityTask(componentName); - startActivity(mainIntent); - } else { - ApptentiveLog.w("Unable to start app's main activity: launch intent is missing"); + if (intent != null) { + ComponentName componentName = intent.getComponent(); + /* Backwards compatible method that will clear all activities in the stack. */ + Intent mainIntent = Util.makeRestartActivityTask(componentName); + if (mainIntent != null) { + startActivity(mainIntent); + } + } else { + ApptentiveLog.w("Unable to start app's main activity: launch intent is missing"); + } } + } catch (Exception e) { + ApptentiveLog.e(e, "Exception while starting app's main activity"); } } diff --git a/apptentive/src/main/java/com/apptentive/android/sdk/util/Constants.java b/apptentive/src/main/java/com/apptentive/android/sdk/util/Constants.java index d801cb7c2..382056f45 100644 --- a/apptentive/src/main/java/com/apptentive/android/sdk/util/Constants.java +++ b/apptentive/src/main/java/com/apptentive/android/sdk/util/Constants.java @@ -9,7 +9,7 @@ public class Constants { public static final int API_VERSION = 9; - private static final String APPTENTIVE_SDK_VERSION = "5.1.1"; + private static final String APPTENTIVE_SDK_VERSION = "5.1.2"; public static final int DEFAULT_CONNECT_TIMEOUT_MILLIS = 45000; public static final int DEFAULT_READ_TIMEOUT_MILLIS = 45000; diff --git a/apptentive/src/main/java/com/apptentive/android/sdk/util/Util.java b/apptentive/src/main/java/com/apptentive/android/sdk/util/Util.java index 5f204888d..52bf5774f 100644 --- a/apptentive/src/main/java/com/apptentive/android/sdk/util/Util.java +++ b/apptentive/src/main/java/com/apptentive/android/sdk/util/Util.java @@ -39,6 +39,7 @@ import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.content.ContextCompat; +import android.support.v4.content.IntentCompat; import android.text.TextUtils; import android.util.Patterns; import android.util.TypedValue; @@ -1192,4 +1193,24 @@ public static String currentDateAsFilename(String prefix, String suffix) { DateFormat df = new SimpleDateFormat("yyyy-MM-dd_hh-mm-ss", Locale.US); return prefix + df.format(new Date()) + suffix; } + + public static @Nullable Intent makeRestartActivityTask(ComponentName cn) { + try { + return makeRestartActivityTaskGuarded(cn); + } + catch (Exception e) { + ApptentiveLog.e(e, "Exception in makeRestartActivityTask"); + } + + return null; + } + + private static Intent makeRestartActivityTaskGuarded(ComponentName cn) { + try { + return Intent.makeRestartActivityTask(cn); + } catch (NoSuchMethodError e) { + //noinspection deprecation + return IntentCompat.makeRestartActivityTask(cn); + } + } }