From 91aebf3fa758edddd40924f06aecdf1be4f12683 Mon Sep 17 00:00:00 2001 From: ChaseApptentive <85038972+ChaseApptentive@users.noreply.github.com> Date: Mon, 26 Sep 2022 11:42:28 -0600 Subject: [PATCH] Apptentive Android SDK 5.8.4 (#239) 5.8.4 release --- CHANGELOG.md | 6 +++ README.md | 2 +- .../android/sdk/ApptentiveInternal.java | 9 +++- .../fragment/MessageCenterFragment.java | 54 ++++++++++++++----- .../android/sdk/util/Constants.java | 3 +- 5 files changed, 56 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bbded492..ec636e55 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +# 2022-09-26 - v5.8.4 + +#### Fixes + +* Support Message Center Push Notifications for Android 13 + # 2022-03-16 - v5.8.3 #### Fixes diff --git a/README.md b/README.md index 8e5cf9ca..490f215d 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.8.3|aar) +##### Binary releases are hosted for Maven [here](http://search.maven.org/#artifactdetails|com.apptentive|apptentive-android|5.8.4|aar) #### Reporting Bugs diff --git a/apptentive/src/main/java/com/apptentive/android/sdk/ApptentiveInternal.java b/apptentive/src/main/java/com/apptentive/android/sdk/ApptentiveInternal.java index 3e44e46d..4afc9056 100644 --- a/apptentive/src/main/java/com/apptentive/android/sdk/ApptentiveInternal.java +++ b/apptentive/src/main/java/com/apptentive/android/sdk/ApptentiveInternal.java @@ -921,8 +921,13 @@ public static PendingIntent prepareMessageCenterPendingIntent(Context context, C } else { intent = MessageCenterInteraction.generateMessageCenterErrorIntent(context); } - return (intent != null) ? PendingIntent.getActivity(context, 0, intent, - PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_UPDATE_CURRENT) : null; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + return PendingIntent.getActivity(context, 0, intent, + PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE); + } else { + return PendingIntent.getActivity(context, 0, intent, + PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_UPDATE_CURRENT); + } } /** diff --git a/apptentive/src/main/java/com/apptentive/android/sdk/module/engagement/interaction/fragment/MessageCenterFragment.java b/apptentive/src/main/java/com/apptentive/android/sdk/module/engagement/interaction/fragment/MessageCenterFragment.java index 7a19012c..ed6ee73d 100644 --- a/apptentive/src/main/java/com/apptentive/android/sdk/module/engagement/interaction/fragment/MessageCenterFragment.java +++ b/apptentive/src/main/java/com/apptentive/android/sdk/module/engagement/interaction/fragment/MessageCenterFragment.java @@ -7,6 +7,18 @@ package com.apptentive.android.sdk.module.engagement.interaction.fragment; +import static com.apptentive.android.sdk.ApptentiveHelper.dispatchConversationTask; +import static com.apptentive.android.sdk.ApptentiveLogTag.MESSAGES; +import static com.apptentive.android.sdk.debug.Assert.assertMainThread; +import static com.apptentive.android.sdk.debug.Assert.assertNotNull; +import static com.apptentive.android.sdk.module.messagecenter.model.MessageCenterListItem.MESSAGE_COMPOSER; +import static com.apptentive.android.sdk.module.messagecenter.model.MessageCenterListItem.MESSAGE_CONTEXT; +import static com.apptentive.android.sdk.module.messagecenter.model.MessageCenterListItem.MESSAGE_OUTGOING; +import static com.apptentive.android.sdk.module.messagecenter.model.MessageCenterListItem.STATUS; +import static com.apptentive.android.sdk.module.messagecenter.model.MessageCenterListItem.WHO_CARD; +import static com.apptentive.android.sdk.util.Util.guarded; +import static com.apptentive.android.sdk.util.Util.hasPermission; + import android.app.Activity; import android.content.Context; import android.content.Intent; @@ -19,8 +31,6 @@ import android.os.Handler; import android.os.Message; import android.os.Parcelable; -import androidx.annotation.Nullable; -import androidx.core.view.ViewCompat; import android.text.Editable; import android.text.TextUtils; import android.view.LayoutInflater; @@ -33,10 +43,13 @@ import android.widget.AbsListView; import android.widget.EditText; +import androidx.annotation.Nullable; +import androidx.core.view.ViewCompat; import androidx.fragment.app.DialogFragment; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentTransaction; import androidx.recyclerview.widget.LinearLayoutManager; + import com.apptentive.android.sdk.Apptentive; import com.apptentive.android.sdk.ApptentiveInternal; import com.apptentive.android.sdk.ApptentiveLog; @@ -62,6 +75,7 @@ import com.apptentive.android.sdk.module.messagecenter.view.holder.MessageComposerHolder; import com.apptentive.android.sdk.util.AnimationUtil; import com.apptentive.android.sdk.util.Constants; +import com.apptentive.android.sdk.util.RuntimeUtils; import com.apptentive.android.sdk.util.StringUtils; import com.apptentive.android.sdk.util.Util; import com.apptentive.android.sdk.util.image.ApptentiveAttachmentLoader; @@ -84,17 +98,6 @@ import java.util.ListIterator; import java.util.Set; -import static com.apptentive.android.sdk.ApptentiveHelper.dispatchConversationTask; -import static com.apptentive.android.sdk.debug.Assert.assertMainThread; -import static com.apptentive.android.sdk.debug.Assert.assertNotNull; -import static com.apptentive.android.sdk.ApptentiveLogTag.MESSAGES; -import static com.apptentive.android.sdk.module.messagecenter.model.MessageCenterListItem.MESSAGE_COMPOSER; -import static com.apptentive.android.sdk.module.messagecenter.model.MessageCenterListItem.MESSAGE_CONTEXT; -import static com.apptentive.android.sdk.module.messagecenter.model.MessageCenterListItem.MESSAGE_OUTGOING; -import static com.apptentive.android.sdk.module.messagecenter.model.MessageCenterListItem.STATUS; -import static com.apptentive.android.sdk.module.messagecenter.model.MessageCenterListItem.WHO_CARD; -import static com.apptentive.android.sdk.util.Util.guarded; - public class MessageCenterFragment extends ApptentiveBaseFragment implements OnListviewItemActionListener, MessageManager.AfterSendMessageListener, @@ -255,6 +258,8 @@ protected boolean execute(Conversation conversation) { // Needed to prevent the window from being pushed up when a text input area is focused. getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_UNCHANGED | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); + + getPushNotificationPermission(); } private void fetchMessages(final FetchCallback callback) { @@ -382,6 +387,9 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) { break; } + case Constants.REQUEST_POST_NOTIFICATION_PERMISSION: { + break; + } default: break; } @@ -1067,7 +1075,7 @@ public void onScrollStateChanged(AbsListView view, int scrollState) { @Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { boolean bCanScrollUp; - if (android.os.Build.VERSION.SDK_INT < 14) { + if (Build.VERSION.SDK_INT < 14) { bCanScrollUp = view.getChildCount() > 0 && (view.getFirstVisiblePosition() > 0 || view.getChildAt(0).getTop() < view.getPaddingTop()); @@ -1669,4 +1677,22 @@ public String getToolbarNavigationContentDescription() { private interface FetchCallback { void onFetchFinish(@Nullable List items); } + + //region push notifications + private void getPushNotificationPermission() { + String POST_NOTIFICATIONS = "android.permission.POST_NOTIFICATIONS"; + + SharedPreferences prefs = ApptentiveInternal.getInstance().getGlobalSharedPrefs(); + + boolean hasPushSetUp = prefs != null && prefs.getInt(Constants.PREF_KEY_PUSH_PROVIDER, -1) != -1 && + prefs.getString(Constants.PREF_KEY_PUSH_TOKEN, null) != null; + + if (hasPushSetUp && + Build.VERSION.SDK_INT >= 33 && + !hasPermission(requireContext(), POST_NOTIFICATIONS) && + RuntimeUtils.getApplicationInfo(requireContext()).getTargetSdkVersion() >= 33) { + requestPermissions(new String[]{POST_NOTIFICATIONS}, Constants.REQUEST_POST_NOTIFICATION_PERMISSION); + } + } + //endregion } 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 414f59d5..af22f0f3 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 = 10; - private static final String APPTENTIVE_SDK_VERSION = "5.8.3"; + private static final String APPTENTIVE_SDK_VERSION = "5.8.4"; public static final int DEFAULT_CONNECT_TIMEOUT_MILLIS = 45000; public static final int DEFAULT_READ_TIMEOUT_MILLIS = 45000; @@ -18,6 +18,7 @@ public class Constants { public static final int REQUEST_CODE_CLOSE_COMPOSING_CONFIRMATION = 20; public final static int REQUEST_READ_STORAGE_PERMISSION = 1; + public final static int REQUEST_POST_NOTIFICATION_PERMISSION = 2; public static final String PREF_NAME = "APPTENTIVE";