Android 13 Updates

Overview

Android 13 (API 33) has rolled out new features and API changes. Refer to Android Behavior changes for Apps targeting Android 13.

There are changes for all apps, whether targeting API 33 or just running on Android 13. Some of these changes include runtime notification permission, Foreground Service Task Manager, and Battery Resource Utilization. For a complete list of these changes, refer to Android Developer documentation.

πŸ“˜

CleverTap Android SDK 4.7.0 supports Android 13

If you plan to increase the target API of your app to 33, you must upgrade the CleverTap Android SDK to version 4.7.0 or higher. The CleverTap SDK version 4.7.0 and higher now support Android SDK from API 19(Android 4.4) and higher.

Push Notification Permission

All apps targeting Android 13 and above must request permission from the user before pushing notifications. All newly-installed apps must get user permission before they can send notifications. This means that you have one chance to ask for permission from the user. However, existing apps will get grandfathered in after a short grace period until the next app launch on Android 13. For more information, refer to Android Developer Documentation - notification permission.

With the latest update, Android 13 allows you to monitor opt-in rates for Push Notifications. To access this feature, ensure you upgrade to SDK version 50100 or higher. As soon as the user grants permission to receive push notifications on the push primer, CleverTap raises an event named Channel Subscribed. And the Channel Unsubscribed event is raised when end-users unsubscribe from the push campaigns. For more information about the event and its properties, refer to System Events.

A Push Primer can explain to your users the need for push notifications and help with your engagement rates. It is an InApp notification that you can show to your users before requesting notification permission. It helps with the following :

  • Allows you to educate your users on why you are asking for this permission before invoking a system dialog that asks the user to allow or deny it.
  • Acts as a precursor to the hard system dialog and thus allows you to ask for permission multiple times if previously denied without making your users search the device settings.

The following are the three ways to handle the new push notification changes:

398

Half Interstitial InApp Notification

398

In-App Alert Notification

293

Push Notification without Push Primer

Invoke Android Permission Dialog (Without Push Primer)

ThepromptForPushPermission(boolean) method is a public method that can be used to request permission on behalf of your application directly. If showFallbackSettings is true, then it shows an alert dialog that routes to the app's notification settings page.

cleverTapAPI.promptForPushPermission(true) //Takes boolean as a parameter. If true and the permission  is denied then we fallback to app’s notification settings, if it’s false then we just throw a verbose log saying permission is denied.
cleverTapAPI.promptForPushPermission(true) // Takes boolean as a parameter. If true and the permission is denied then we fallback to app’s notification settings, if it’s false then we just throw a verbose log saying permission is denied.

Check Status of Push Permission

The isPushPermissionGranted method can be used to check the status of the push notification permission for your application.

cleverTapAPI.isPushPermissionGranted() // Returns true if permission is granted, else returns false if permission is denied.
cleverTapAPI.isPushPermissionGranted // Returns true if permission is granted, else returns false if permission is denied.

Invoke Push Primer Flow

promptPushPrimer(JSONObject)- Calls the push primer flow for Android 13 and above devices.

cleverTapAPI.promptPushPrimer(jsonObject);

Available Callbacks for Push Primer

Based on notification permission grant/deny, we provide a callback on PushPermissionResponse(boolean).

  • Register PushPermissionResponseListener instance to receive the Push Primer result:
    The CleverTapAPI class exposes a registerPushPermissionNotificationResponseListener(PushPermissionResponseListener) method. Use this method to register your PushPermissionResponseListener instance. Each PushPermissionResponseListener instance passed in this method is added to a List of the PushPermissionResponseListener type, and the Push Primer result is notified to all the elements of that list.

  • Unregister PushPermissionResponseListener instance to stop receiving the Push Primer result:
    The CleverTapAPI class exposes a unregisterPushPermissionNotificationResponseListener(PushPermissionResponseListener) method.
    Use this method to unregister your previously registered PushPermissionResponseListener instance.

πŸ“˜

Note

Call registerPushPermissionNotificationResponseListener(PushPermissionResponseListener) only from the onCreate() method of the Activity/Fragment and unregister the listener instance from the onDestroy() method using unregisterPushPermissionNotificationResponseListener(PushPermissionResponseListener).

The following is a sample implementation to get the permission result:

public class MainActivity extends AppCompatActivity implements PushPermissionResponseListener {
    private CleverTapAPI cleverTapDefaultInstance;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        cleverTapDefaultInstance = CleverTapAPI.getDefaultInstance(this);
        if (cleverTapDefaultInstance != null) {
            cleverTapDefaultInstance.registerPushPermissionNotificationResponseListener(this);
        }
    }

    @Override
    public void onPushPermissionResponse(boolean accepted) {
        Log.i(TAG, "onPushPermissionResponse :  InApp---> response() called accepted="+accepted);
        if(accepted){
            CleverTapAPI.createNotificationChannel(getApplicationContext(), "BRTesting", "Testing Channel",
                    "Testing Channel for BR", NotificationManager.IMPORTANCE_HIGH, true);
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (cleverTapDefaultInstance != null) {
            cleverTapDefaultInstance.unregisterPushPermissionNotificationResponseListener(this);
        }
    }
}
class MainActivity : AppCompatActivity(), PushPermissionResponseListener {
    var cleverTapDefaultInstance: CleverTapAPI? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        cleverTapDefaultInstance = CleverTapAPI.getDefaultInstance(this)
        cleverTapDefaultInstance?.registerPushPermissionNotificationResponseListener(this)
    }

    override fun onPushPermissionResponse(accepted: Boolean) {
        Log.i(TAG, "onPushPermissionResponse :  InApp---> response() called accepted=$accepted")
        if (accepted) {
            CleverTapAPI.createNotificationChannel(getApplicationContext(), "BRTesting", "Testing Channel",
                "Testing Channel for BR", NotificationManager.IMPORTANCE_HIGH, true);
        }
    }

    override fun onDestroy() {
        super.onDestroy()
        cleverTapDefaultInstance?.unregisterPushPermissionNotificationResponseListener(this)
    }
}

πŸ“˜

New Method for InAppNotificationListener

Use the following method from CleverTap SDK version 4.7.0 and above:

@Override  
public void onShow(CTInAppNotification ctInAppNotification) {
}