Speedify SDK for Android  15.0.0
Service Notification

The main processing and VPN service of the Speedify SDK is done in an Android foreground service running in a background process. Starting with Android Oreo, foreground services are required to have a notification visible at all times. Prior to Oreo it is still recommened to have this notification so that the OS knows that the service is important, and that it should not be killed in low memory situations.

As of Android 13, POST_NOTIFICATIONS permission is required to show the foreground service notification.

// notification permission is required for foreground service notification to show
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.TIRAMISU) {
NotificationManager mNotifyMgr = (NotificationManager) getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
if (!mNotifyMgr.areNotificationsEnabled()) {
ActivityCompat.requestPermissions(this, new String[] { android.Manifest.permission.POST_NOTIFICATIONS }, 100);
}
}

The default SpeedifyHandler provided by the Speedify SDK implements a notification for the foreground service, complete with connect, disconnect, and exit controls.

The text of this notification is customizable via the default service notification resource strings outlined in SDK Strings.

The default icon used is drawable resource named speedify_notification_icon. This can be overridden via setServiceNotificationIcon.

The default click action is to launch the main launcher intent of the application, as returned by PackageManager.getLaunchIntentForPackage. This can be overridden via setServiceNotificationLaunchIntent.

If you want to completely customize the notification, you can override UpdateForegroundNotification and HideForegroundNotification in SpeedifyHandler, and provide your own notification. You must also use a notification ID of SpeedifyHandler.SPEEDIFY_FOREGROUND_NOTIFICATION_ID to replace the temporary minimal foreground notification that is generated to avoid ANRs. The notification channel used is SpeedifyHandler.SPEEDIFY_FOREGROUND_CHANNEL_ID.

NOTE : UpdateForegroundNotification and HideForegroundNotification are called from the background process. You will not be able to access objects running in your UI process.

mySpeedifySDKObject.setHandler(new SpeedifyHandler() {
@Override
public void UpdateForegroundNotification(Service service, Types.State state, String serverName, boolean killswitchActive) {
NotificationCompat.Builder builder = new NotificationCompat.Builder(service, MY_NOTIFICATION_CHANNEL_ID);
builder.setContentTitle("MyVPN").setContentText(state.toString()).setSmallIcon(R.drawable.notification_icon);
Notification n = builder.build();
service.startForeground(MY_FOREGROUND_NOTIFICATION_ID, n);
}
@Override
public void HideForegroundNotification(Service service) {
NotificationManager nMgr = (NotificationManager) service.getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
nMgr.cancel(MY_FOREGROUND_NOTIFICATION_ID);
}
});