From 67e9ac53d37226af018d7eab7a912bc2e41c76d8 Mon Sep 17 00:00:00 2001 From: VitaliyDovbnya Date: Thu, 19 Sep 2024 18:02:46 +0300 Subject: [PATCH] 4.5.0-conference-java --- sample-conference-java/app/build.gradle | 13 +- sample-conference-java/app/proguard-rules.pro | 9 +- .../app/src/main/AndroidManifest.xml | 20 +- .../sample/videochat/conference/java/App.java | 8 +- .../java/activities/ChatActivity.java | 183 ++++++++++++------ .../java/activities/SplashActivity.java | 28 +++ .../conference/java/managers/ChatHelper.java | 5 - .../conference/java/services/CallService.java | 81 +++++--- .../java/utils/SystemPermissionsHelper.java | 37 +++- sample-conference-java/build.gradle | 14 +- sample-conference-java/gradle.properties | 7 +- .../gradle/wrapper/gradle-wrapper.properties | 2 +- 12 files changed, 287 insertions(+), 120 deletions(-) diff --git a/sample-conference-java/app/build.gradle b/sample-conference-java/app/build.gradle index b09a8c308..b9b3f2ca4 100644 --- a/sample-conference-java/app/build.gradle +++ b/sample-conference-java/app/build.gradle @@ -18,19 +18,17 @@ repositories { android { def versionQACode = 1 - compileSdkVersion 31 - buildToolsVersion "31.0.0" - flavorDimensions dimensionDefault - defaultConfig { + compileSdk 34 applicationId "com.quickblox.sample.videochat.conference.java" minSdkVersion 21 - targetSdkVersion 31 - versionCode 441000 - versionName '4.4.1' + targetSdkVersion 34 + versionCode 450000 + versionName '4.5.0' multiDexEnabled true } + flavorDimensions dimensionDefault productFlavors { dev { dimension dimensionDefault @@ -80,6 +78,7 @@ android { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } + namespace 'com.quickblox.sample.videochat.conference.java' } dependencies { diff --git a/sample-conference-java/app/proguard-rules.pro b/sample-conference-java/app/proguard-rules.pro index e96593440..50f3cb291 100755 --- a/sample-conference-java/app/proguard-rules.pro +++ b/sample-conference-java/app/proguard-rules.pro @@ -44,4 +44,11 @@ -keep class com.bumptech.** { *; } # google gms --keep class com.google.android.gms.** { *; } \ No newline at end of file +-keep class com.google.android.gms.** { *; } + +#json +-keep class org.json.** { *; } + +-keep class com.google.gson.reflect.TypeToken +-keep class * extends com.google.gson.reflect.TypeToken +-keep public class * implements java.lang.reflect.Type \ No newline at end of file diff --git a/sample-conference-java/app/src/main/AndroidManifest.xml b/sample-conference-java/app/src/main/AndroidManifest.xml index 85c7f5308..b8e3ae6b2 100644 --- a/sample-conference-java/app/src/main/AndroidManifest.xml +++ b/sample-conference-java/app/src/main/AndroidManifest.xml @@ -1,7 +1,6 @@ + xmlns:tools="http://schemas.android.com/tools"> @@ -10,13 +9,24 @@ - - + + + + + + + + + Build.VERSION_CODES.TIRAMISU) { + requestSharingPermissions(this, REQUEST_START_CONFERENCE_PERMISSION_CODE); + } else { + startConference(qbChatDialog.getDialogId(), currentUser.getId(), qbChatDialog.getOccupants()); + } } } + public static void requestSharingPermissions(Activity context, int requestCode) { + MediaProjectionManager mediaProjectionManager = (MediaProjectionManager) context.getSystemService(MEDIA_PROJECTION_SERVICE); + context.startActivityForResult(mediaProjectionManager.createScreenCaptureIntent(), requestCode); + } + + public static void requestSharingPermissionsForJoinScreen(Activity context, String streamerName, int requestCode) { + MediaProjectionManager mediaProjectionManager = (MediaProjectionManager) context.getSystemService(MEDIA_PROJECTION_SERVICE); + + Intent intent = mediaProjectionManager.createScreenCaptureIntent(); + intent.putExtra(EXTRA_STREAMER_NAME, streamerName); + context.startActivityForResult(intent, requestCode); + } + private void startConference(final String dialogID, Integer userID, final List occupants) { Log.d(TAG, "Start (Join) Conference : " + dialogID); showProgressDialog(R.string.join_conference); @@ -548,7 +577,11 @@ private void checkStreamPermissions() { if (needToAskPermissions) { PermissionsActivity.startForResult(this, REQUEST_STREAM_PERMISSION_CODE, Consts.PERMISSIONS); } else { - startStream(streamID); + if (Build.VERSION.SDK_INT > Build.VERSION_CODES.TIRAMISU) { + requestSharingPermissions(this, REQUEST_START_STREAM_PERMISSION_CODE); + } else { + startStream(streamID); + } } } @@ -804,8 +837,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == RESULT_OK) { if (requestCode == REQUEST_CODE_SELECT_PEOPLE && data != null) { progressBar.setVisibility(View.VISIBLE); - final ArrayList selectedUsers = (ArrayList) data.getSerializableExtra( - SelectUsersActivity.EXTRA_QB_USERS); + final ArrayList selectedUsers = (ArrayList) data.getSerializableExtra(SelectUsersActivity.EXTRA_QB_USERS); List existingOccupantsIds = qbChatDialog.getOccupants(); final List newUsersIds = new ArrayList<>(); @@ -845,12 +877,42 @@ public void onError(QBResponseException e) { checkStreamPermissions(); } } + + if (requestCode == REQUEST_START_CONFERENCE_PERMISSION_CODE) { + if (resultCode == Activity.RESULT_OK) { + startConference(qbChatDialog.getDialogId(), currentUser.getId(), qbChatDialog.getOccupants()); + } else { + ToastUtils.shortToast(getApplicationContext(), "Permission should be granted for the application to function correctly."); + } + } + + if (requestCode == REQUEST_START_STREAM_PERMISSION_CODE) { + if (resultCode == Activity.RESULT_OK) { + startStream(streamID); + } else { + ToastUtils.shortToast(getApplicationContext(), "Permission should be granted for the application to function correctly."); + } + } + + if (requestCode == REQUEST_JOIN_STREAM_PERMISSION_CODE) { + if (resultCode == Activity.RESULT_OK) { + String streamerName = data.getStringExtra(EXTRA_STREAMER_NAME); + joinStream(streamID, streamerName); + + } else { + ToastUtils.shortToast(getApplicationContext(), "Permission should be granted for the application to function correctly."); + } + } } @Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { super.onRequestPermissionsResult(requestCode, permissions, grantResults); - if (requestCode == PERMISSIONS_FOR_SAVE_FILE_IMAGE_REQUEST && grantResults[0] != -1) { + if (requestCode == PERMISSIONS_FOR_SAVE_FILE_IMAGE_REQUEST && grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { + openImagePicker(); + } + + if (requestCode == PERMISSIONS_FOR_MEDIA_REQUEST && grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { openImagePicker(); } } @@ -860,7 +922,7 @@ public void onMediaPicked(int requestCode, File file) { switch (requestCode) { case REQUEST_CODE_ATTACHMENT: SystemPermissionsHelper permissionsHelper = new SystemPermissionsHelper(this); - if (permissionsHelper.isSaveImagePermissionGranted()) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU || permissionsHelper.isSaveImagePermissionGranted()) { attachmentPreviewAdapter.add(file); } else { permissionsHelper.requestPermissionsForSaveFileImage(); @@ -960,30 +1022,46 @@ public void onClick(View v) { } }); - attachmentPreviewAdapter = new AttachmentPreviewAdapter(this, - new AttachmentPreviewAdapter.AttachmentCountChangedListener() { - @Override - public void onAttachmentCountChanged(int count) { - attachmentPreviewContainerLayout.setVisibility(count == 0 ? View.GONE : View.VISIBLE); - } - }, - new AttachmentPreviewAdapter.AttachmentUploadErrorListener() { + attachmentPreviewAdapter = new AttachmentPreviewAdapter(this, new AttachmentPreviewAdapter.AttachmentCountChangedListener() { + @Override + public void onAttachmentCountChanged(int count) { + attachmentPreviewContainerLayout.setVisibility(count == 0 ? View.GONE : View.VISIBLE); + } + }, new AttachmentPreviewAdapter.AttachmentUploadErrorListener() { + @Override + public void onAttachmentUploadError(QBResponseException e) { + showErrorSnackbar(0, e, new View.OnClickListener() { @Override - public void onAttachmentUploadError(QBResponseException e) { - showErrorSnackbar(0, e, new View.OnClickListener() { - @Override - public void onClick(View v) { - openImagePicker(); - } - }); + public void onClick(View v) { + openImagePicker(); } }); + } + }); AttachmentPreviewAdapterView previewAdapterView = findViewById(R.id.adapter_attachment_preview); previewAdapterView.setAdapter(attachmentPreviewAdapter); } private void openImagePicker() { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + checkCameraAndMediaPermissions(); + } else { + checkCameraAndStoragePermissions(); + } + } + + @RequiresApi(api = Build.VERSION_CODES.TIRAMISU) + private void checkCameraAndMediaPermissions() { + SystemPermissionsHelper permissionHelper = new SystemPermissionsHelper(this); + if (permissionHelper.isMediaPermissionsGranted()) { + MediaPickHelper.pickAnImage(this, REQUEST_CODE_ATTACHMENT); + } else { + permissionHelper.requestPermissionsForMedia(); + } + } + + private void checkCameraAndStoragePermissions() { SystemPermissionsHelper permissionHelper = new SystemPermissionsHelper(this); if (permissionHelper.isSaveImagePermissionGranted()) { MediaPickHelper.pickAnImage(this, REQUEST_CODE_ATTACHMENT); @@ -1002,8 +1080,7 @@ private void initMessagesRecyclerView() { messagesList = new ArrayList<>(); chatAdapter = new ChatAdapter(getApplicationContext(), qbChatDialog, messagesList); chatAdapter.setPaginationHistoryListener(new PaginationListener()); - chatMessagesRecyclerView.addItemDecoration( - new StickyRecyclerHeadersDecoration(chatAdapter)); + chatMessagesRecyclerView.addItemDecoration(new StickyRecyclerHeadersDecoration(chatAdapter)); chatMessagesRecyclerView.setAdapter(chatAdapter); imageAttachClickListener = new ImageAttachClickListener(); @@ -1132,27 +1209,24 @@ private void notifyUsersAboutCreatingDialog() { } private void updateDialogUsers(final ArrayList selectedUsers) { - getChatHelper().updateDialogUsers(currentUser, qbChatDialog, selectedUsers, - new QBEntityCallback() { - @Override - public void onSuccess(QBChatDialog dialog, Bundle args) { - qbChatDialog = dialog; - loadDialogUsers(); - } + getChatHelper().updateDialogUsers(currentUser, qbChatDialog, selectedUsers, new QBEntityCallback() { + @Override + public void onSuccess(QBChatDialog dialog, Bundle args) { + qbChatDialog = dialog; + loadDialogUsers(); + } + @Override + public void onError(QBResponseException e) { + hideProgressDialog(); + showErrorSnackbar(R.string.chat_info_add_people_error, e, new View.OnClickListener() { @Override - public void onError(QBResponseException e) { - hideProgressDialog(); - showErrorSnackbar(R.string.chat_info_add_people_error, e, - new View.OnClickListener() { - @Override - public void onClick(View v) { - updateDialogUsers(selectedUsers); - } - }); + public void onClick(View v) { + updateDialogUsers(selectedUsers); } - } - ); + }); + } + }); } private void loadDialogUsers() { @@ -1166,13 +1240,12 @@ public void onSuccess(ArrayList users, Bundle bundle) { @Override public void onError(QBResponseException e) { progressBar.setVisibility(View.GONE); - showErrorSnackbar(R.string.chat_load_users_error, e, - new View.OnClickListener() { - @Override - public void onClick(View v) { - loadDialogUsers(); - } - }); + showErrorSnackbar(R.string.chat_load_users_error, e, new View.OnClickListener() { + @Override + public void onClick(View v) { + loadDialogUsers(); + } + }); } }); } @@ -1322,7 +1395,12 @@ private void startSuitableConversation(QBChatMessage qbChatMessage) { } else { QBUser streamer = getQBUsersHolder().getUserById(qbChatMessage.getSenderId()); String streamerName = TextUtils.isEmpty(streamer.getFullName()) ? streamer.getLogin() : streamer.getFullName(); - joinStream(streamID, streamerName); + + if (Build.VERSION.SDK_INT > Build.VERSION_CODES.TIRAMISU) { + requestSharingPermissionsForJoinScreen(this, streamerName, REQUEST_JOIN_STREAM_PERMISSION_CODE); + } else { + joinStream(streamID, streamerName); + } } } } @@ -1522,9 +1600,7 @@ private String makeStringFromNames() { if (firstUser.length() <= 20) { result = firstUser + " " + getString(R.string.typing_postfix_singular); } else { - result = firstUser.subSequence(0, 19).toString() + - getString(R.string.typing_ellipsis) + - " " + getString(R.string.typing_postfix_singular); + result = firstUser.subSequence(0, 19).toString() + getString(R.string.typing_ellipsis) + " " + getString(R.string.typing_postfix_singular); } } else if (usersCount == 2) { @@ -1558,8 +1634,7 @@ private String makeStringFromNames() { if (secondUser.length() >= 10) { secondUser = secondUser.subSequence(0, 9).toString() + getString(R.string.typing_ellipsis); } - result = firstUser + ", " + secondUser + - " and " + (currentTypingUserNames.size() - 2) + " more " + getString(R.string.typing_postfix_plural); + result = firstUser + ", " + secondUser + " and " + (currentTypingUserNames.size() - 2) + " more " + getString(R.string.typing_postfix_plural); } } return result; diff --git a/sample-conference-java/app/src/main/java/com/quickblox/sample/videochat/conference/java/activities/SplashActivity.java b/sample-conference-java/app/src/main/java/com/quickblox/sample/videochat/conference/java/activities/SplashActivity.java index 46edae474..c0115138b 100644 --- a/sample-conference-java/app/src/main/java/com/quickblox/sample/videochat/conference/java/activities/SplashActivity.java +++ b/sample-conference-java/app/src/main/java/com/quickblox/sample/videochat/conference/java/activities/SplashActivity.java @@ -1,17 +1,23 @@ package com.quickblox.sample.videochat.conference.java.activities; +import static com.quickblox.sample.videochat.conference.java.utils.SystemPermissionsHelper.REQUEST_CADE_FOR_NOTIFICATION; + import android.content.pm.PackageManager; +import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.util.Log; import android.view.View; import android.widget.TextView; +import androidx.annotation.NonNull; + import com.quickblox.auth.session.QBSessionManager; import com.quickblox.chat.QBChatService; import com.quickblox.core.QBEntityCallback; import com.quickblox.core.exception.QBResponseException; import com.quickblox.sample.videochat.conference.java.R; +import com.quickblox.sample.videochat.conference.java.utils.SystemPermissionsHelper; import com.quickblox.users.model.QBUser; @@ -28,6 +34,20 @@ protected void onCreate(Bundle savedInstanceState) { getSupportActionBar().hide(); } fillVersion(); + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + SystemPermissionsHelper permissionsHelper = new SystemPermissionsHelper(this); + boolean isNotNotificationPermissionGranted = !permissionsHelper.isNotificationPermissionGranted(); + if (isNotNotificationPermissionGranted) { + permissionsHelper.requestPermissionsForNotification(); + return; + } + } + + start(); + } + + private void start() { new Handler().postDelayed(new Runnable() { @Override public void run() { @@ -41,6 +61,14 @@ public void run() { }, SPLASH_DELAY); } + @Override + public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { + super.onRequestPermissionsResult(requestCode, permissions, grantResults); + if (requestCode == REQUEST_CADE_FOR_NOTIFICATION) { + start(); + } + } + @Override public void onBackPressed() { diff --git a/sample-conference-java/app/src/main/java/com/quickblox/sample/videochat/conference/java/managers/ChatHelper.java b/sample-conference-java/app/src/main/java/com/quickblox/sample/videochat/conference/java/managers/ChatHelper.java index 7c1950846..dcef94146 100644 --- a/sample-conference-java/app/src/main/java/com/quickblox/sample/videochat/conference/java/managers/ChatHelper.java +++ b/sample-conference-java/app/src/main/java/com/quickblox/sample/videochat/conference/java/managers/ChatHelper.java @@ -186,20 +186,15 @@ public void updateDialogUsers(QBUser currentUser, QBChatDialog qbDialog, final List newQbDialogUsersList, QBEntityCallback callback) { List addedUsers = QBDialogUtils.getAddedUsers(context, currentUser, qbDialog, newQbDialogUsersList); - List removedUsers = QBDialogUtils.getRemovedUsers(context, currentUser, qbDialog, newQbDialogUsersList); QBDialogUtils.logDialogUsers(context, qbDialog); QBDialogUtils.logUsers(addedUsers); Log.w(TAG, "======================="); - QBDialogUtils.logUsers(removedUsers); QBDialogRequestBuilder qbRequestBuilder = new QBDialogRequestBuilder(); if (!addedUsers.isEmpty()) { qbRequestBuilder.addUsers(addedUsers.toArray(new QBUser[addedUsers.size()])); } - if (!removedUsers.isEmpty()) { - qbRequestBuilder.removeUsers(removedUsers.toArray(new QBUser[removedUsers.size()])); - } QBRestChatService.updateChatDialog(qbDialog, qbRequestBuilder).performAsync(new QBEntityCallback() { @Override diff --git a/sample-conference-java/app/src/main/java/com/quickblox/sample/videochat/conference/java/services/CallService.java b/sample-conference-java/app/src/main/java/com/quickblox/sample/videochat/conference/java/services/CallService.java index 7f34c969d..aa7745002 100644 --- a/sample-conference-java/app/src/main/java/com/quickblox/sample/videochat/conference/java/services/CallService.java +++ b/sample-conference-java/app/src/main/java/com/quickblox/sample/videochat/conference/java/services/CallService.java @@ -7,6 +7,7 @@ import android.app.Service; import android.content.Context; import android.content.Intent; +import android.content.pm.ServiceInfo; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.os.Binder; @@ -32,7 +33,6 @@ import com.quickblox.sample.videochat.conference.java.activities.CallActivity; import com.quickblox.sample.videochat.conference.java.managers.WebRtcSessionManager; import com.quickblox.sample.videochat.conference.java.utils.Consts; -import com.quickblox.videochat.webrtc.AppRTCAudioManager; import com.quickblox.videochat.webrtc.BaseSession; import com.quickblox.videochat.webrtc.QBMediaStreamManager; import com.quickblox.videochat.webrtc.QBRTCAudioTrack; @@ -40,6 +40,7 @@ import com.quickblox.videochat.webrtc.QBRTCConfig; import com.quickblox.videochat.webrtc.QBRTCScreenCapturer; import com.quickblox.videochat.webrtc.QBRTCTypes; +import com.quickblox.videochat.webrtc.audio.QBAudioManager; import com.quickblox.videochat.webrtc.callbacks.QBRTCClientAudioTracksCallback; import com.quickblox.videochat.webrtc.callbacks.QBRTCClientVideoTracksCallbacks; import com.quickblox.videochat.webrtc.callbacks.QBRTCSessionStateCallback; @@ -80,7 +81,7 @@ public class CallService extends Service { private OnlineParticipantsChangeListener onlineParticipantsChangeListener; private OnlineParticipantsCheckerCountdown onlineParticipantsCheckerCountdown; private UsersConnectDisconnectCallback usersConnectDisconnectCallback; - private AppRTCAudioManager audioManager; + private QBAudioManager audioManager; private boolean sharingScreenState = false; private String roomID; private String roomTitle; @@ -128,22 +129,47 @@ public void onCreate() { @Override public int onStartCommand(Intent intent, int flags, int startId) { Notification notification = initNotification(); - startForeground(SERVICE_ID, notification); - if (intent != null) { - roomID = intent.getStringExtra(Consts.EXTRA_ROOM_ID); - roomTitle = intent.getStringExtra(Consts.EXTRA_ROOM_TITLE); - dialogID = intent.getStringExtra(Consts.EXTRA_DIALOG_ID); - opponentsIDsList = (ArrayList) intent.getSerializableExtra(Consts.EXTRA_DIALOG_OCCUPANTS); - asListenerRole = intent.getBooleanExtra(Consts.EXTRA_AS_LISTENER, false); - - if (!isListenerRole() && !roomID.equals(dialogID)) { - onlineParticipantsCheckerCountdown = new OnlineParticipantsCheckerCountdown(Long.MAX_VALUE, 3000); - onlineParticipantsCheckerCountdown.start(); + try { + if (Build.VERSION.SDK_INT > Build.VERSION_CODES.TIRAMISU) { + int foregroundServiceType = getServiceType(isVideoSession(currentSession)); + startForeground(SERVICE_ID, notification, foregroundServiceType); + } else { + startForeground(SERVICE_ID, notification); } + + if (intent != null) { + roomID = intent.getStringExtra(Consts.EXTRA_ROOM_ID); + roomTitle = intent.getStringExtra(Consts.EXTRA_ROOM_TITLE); + dialogID = intent.getStringExtra(Consts.EXTRA_DIALOG_ID); + opponentsIDsList = (ArrayList) intent.getSerializableExtra(Consts.EXTRA_DIALOG_OCCUPANTS); + asListenerRole = intent.getBooleanExtra(Consts.EXTRA_AS_LISTENER, false); + + if (!isListenerRole() && !roomID.equals(dialogID + )) { + onlineParticipantsCheckerCountdown = new OnlineParticipantsCheckerCountdown(Long.MAX_VALUE, 3000); + onlineParticipantsCheckerCountdown.start(); + } + } + } catch (RuntimeException exception) { + // handle exception. } + return super.onStartCommand(intent, flags, startId); } + @RequiresApi(api = Build.VERSION_CODES.R) + private int getServiceType(boolean isVideoSession) { + if (isVideoSession) { + return ServiceInfo.FOREGROUND_SERVICE_TYPE_CAMERA | ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PROJECTION; + } else { + return ServiceInfo.FOREGROUND_SERVICE_TYPE_MICROPHONE; + } + } + + private boolean isVideoSession(ConferenceSession session) { + return session != null && session.getConferenceType() == QBRTCTypes.QBConferenceType.QB_CONFERENCE_TYPE_VIDEO; + } + @Override public void onDestroy() { super.onDestroy(); @@ -175,8 +201,7 @@ private Notification initNotification() { intentFlag = PendingIntent.FLAG_IMMUTABLE; } - PendingIntent notifyPendingIntent = PendingIntent.getActivity(this, 0, - notifyIntent, intentFlag); + PendingIntent notifyPendingIntent = PendingIntent.getActivity(this, 0, notifyIntent, intentFlag); String notificationTitle = getString(R.string.notification_title); String notificationText = getString(R.string.notification_text, ""); @@ -186,9 +211,7 @@ private Notification initNotification() { bigTextStyle.setBigContentTitle(notificationTitle); bigTextStyle.bigText(notificationText); - String channelID = Build.VERSION.SDK_INT >= Build.VERSION_CODES.O ? - createNotificationChannel(CHANNEL_ID, CHANNEL_NAME) - : getString(R.string.app_name); + String channelID = Build.VERSION.SDK_INT >= Build.VERSION_CODES.O ? createNotificationChannel(CHANNEL_ID, CHANNEL_NAME) : getString(R.string.app_name); NotificationCompat.Builder builder = new NotificationCompat.Builder(this, channelID); builder.setStyle(bigTextStyle); @@ -261,8 +284,8 @@ private void initListeners() { private void initAudioManager() { if (audioManager == null) { - audioManager = AppRTCAudioManager.create(this); - audioManager.selectAudioDevice(AppRTCAudioManager.AudioDevice.SPEAKER_PHONE); + audioManager = QBAudioManager.create(this); + audioManager.selectAudioDevice(QBAudioManager.AudioDevice.SPEAKER_PHONE); previousDeviceEarPiece = false; Log.d(TAG, "AppRTCAudioManager.AudioDevice.SPEAKER_PHONE"); @@ -270,19 +293,17 @@ private void initAudioManager() { if (!plugged) { if (previousDeviceEarPiece) { - setAudioDeviceDelayed(AppRTCAudioManager.AudioDevice.EARPIECE); + setAudioDeviceDelayed(QBAudioManager.AudioDevice.EARPIECE); } else { - setAudioDeviceDelayed(AppRTCAudioManager.AudioDevice.SPEAKER_PHONE); + setAudioDeviceDelayed(QBAudioManager.AudioDevice.SPEAKER_PHONE); } } }); - audioManager.start((audioDevice, set) -> - Log.d(TAG, "Audio Device Switched to " + audioDevice) - ); + audioManager.start((audioDevice, set) -> Log.d(TAG, "Audio Device Switched to " + audioDevice)); } } - private void setAudioDeviceDelayed(final AppRTCAudioManager.AudioDevice audioDevice) { + private void setAudioDeviceDelayed(final QBAudioManager.AudioDevice audioDevice) { new Handler().postDelayed(() -> audioManager.selectAudioDevice(audioDevice), 500); } @@ -400,8 +421,7 @@ public boolean isListenerRole() { } public void setAudioEnabled(boolean enabled) { - if (currentSession != null && currentSession.getMediaStreamManager() != null - && currentSession.getMediaStreamManager().getLocalAudioTrack() != null) { + if (currentSession != null && currentSession.getMediaStreamManager() != null && currentSession.getMediaStreamManager().getLocalAudioTrack() != null) { currentSession.getMediaStreamManager().getLocalAudioTrack().setEnabled(enabled); } } @@ -826,9 +846,6 @@ public interface ReconnectionListener { } public enum ReconnectionState { - COMPLETED, - IN_PROGRESS, - FAILED, - DEFAULT + COMPLETED, IN_PROGRESS, FAILED, DEFAULT } } \ No newline at end of file diff --git a/sample-conference-java/app/src/main/java/com/quickblox/sample/videochat/conference/java/utils/SystemPermissionsHelper.java b/sample-conference-java/app/src/main/java/com/quickblox/sample/videochat/conference/java/utils/SystemPermissionsHelper.java index 97abbf83e..81e593de3 100644 --- a/sample-conference-java/app/src/main/java/com/quickblox/sample/videochat/conference/java/utils/SystemPermissionsHelper.java +++ b/sample-conference-java/app/src/main/java/com/quickblox/sample/videochat/conference/java/utils/SystemPermissionsHelper.java @@ -3,14 +3,18 @@ import android.Manifest; import android.app.Activity; import android.content.pm.PackageManager; +import android.os.Build; -import java.util.ArrayList; - +import androidx.annotation.RequiresApi; import androidx.core.app.ActivityCompat; import androidx.core.content.ContextCompat; +import java.util.ArrayList; + public class SystemPermissionsHelper { private static final int PERMISSIONS_FOR_SAVE_FILE_IMAGE_REQUEST = 1010; + public static final int REQUEST_CADE_FOR_NOTIFICATION = 1020; + public static final int PERMISSIONS_FOR_MEDIA_REQUEST = 1030; private Activity activity; @@ -35,6 +39,35 @@ public void requestPermissionsForSaveFileImage() { checkAndRequestPermissions(PERMISSIONS_FOR_SAVE_FILE_IMAGE_REQUEST, permissions); } + + @RequiresApi(api = Build.VERSION_CODES.TIRAMISU) + public boolean isMediaPermissionsGranted() { + return isPermissionGranted(Manifest.permission.READ_MEDIA_IMAGES) + && isPermissionGranted(Manifest.permission.READ_MEDIA_VIDEO) + && isPermissionGranted(Manifest.permission.CAMERA); + } + + @RequiresApi(api = Build.VERSION_CODES.TIRAMISU) + public void requestPermissionsForMedia() { + ArrayList permissions = new ArrayList<>(); + permissions.add(Manifest.permission.READ_MEDIA_IMAGES); + permissions.add(Manifest.permission.READ_MEDIA_VIDEO); + permissions.add(Manifest.permission.CAMERA); + checkAndRequestPermissions(PERMISSIONS_FOR_MEDIA_REQUEST, permissions); + } + + @RequiresApi(api = Build.VERSION_CODES.TIRAMISU) + public boolean isNotificationPermissionGranted() { + return isPermissionGranted(Manifest.permission.POST_NOTIFICATIONS); + } + + @RequiresApi(api = Build.VERSION_CODES.TIRAMISU) + public void requestPermissionsForNotification() { + ArrayList permissions = new ArrayList<>(); + permissions.add(Manifest.permission.POST_NOTIFICATIONS); + checkAndRequestPermissions(REQUEST_CADE_FOR_NOTIFICATION, permissions); + } + private void checkAndRequestPermissions(int requestCode, ArrayList permissions) { if (collectDeniedPermissions(permissions).length > 0) { requestPermissions(requestCode, collectDeniedPermissions(permissions)); diff --git a/sample-conference-java/build.gradle b/sample-conference-java/build.gradle index 8fe09fc8a..a3726f62d 100644 --- a/sample-conference-java/build.gradle +++ b/sample-conference-java/build.gradle @@ -5,8 +5,8 @@ buildscript { } dependencies { - classpath 'com.android.tools.build:gradle:4.2.2' - classpath 'com.google.gms:google-services:4.3.10' + classpath 'com.android.tools.build:gradle:8.2.2' + classpath 'com.google.gms:google-services:4.4.2' } } @@ -21,24 +21,24 @@ ext { dimensionDefault = 'default' // QuickBlox SDK version - qbSdkVersion = '3.9.17' + qbSdkVersion = '4.1.3' // Firebase - firebaseCoreVersion = '21.0.0' + firebaseCoreVersion = '21.1.1' // Material - materialVersion = '1.6.1' + materialVersion = '1.12.0' // Android X fragmentAndroidXVersion = '1.4.1' lifecycleViewmodelAndroidXVersion = '2.4.1' - coreKtxVersion = '1.7.0' + coreKtxVersion = '1.13.1' // RobotoTextView robotoTextViewVersion = '4.0.0' // Glide - glideVersion = '4.12.0' + glideVersion = '4.15.0' // CircleImageView circleImageVersion = "2.1.0" diff --git a/sample-conference-java/gradle.properties b/sample-conference-java/gradle.properties index 3f56b1941..e20c795f7 100644 --- a/sample-conference-java/gradle.properties +++ b/sample-conference-java/gradle.properties @@ -10,7 +10,7 @@ # Specifies the JVM arguments used for the daemon process. # The setting is particularly useful for tweaking memory settings. # Default value: -Xmx10248m -XX:MaxPermSize=256m -org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 +org.gradle.jvmargs=-Xmx1024m org.gradle.daemon=true # When configured, Gradle will run in incubating parallel mode. @@ -19,4 +19,7 @@ org.gradle.daemon=true org.gradle.parallel=true org.gradle.configureondemand=true android.useAndroidX=true -android.enableJetifier=true \ No newline at end of file +android.enableJetifier=true +android.defaults.buildfeatures.buildconfig=true +android.nonTransitiveRClass=false +android.nonFinalResIds=false \ No newline at end of file diff --git a/sample-conference-java/gradle/wrapper/gradle-wrapper.properties b/sample-conference-java/gradle/wrapper/gradle-wrapper.properties index 4d9ca1649..15de90249 100644 --- a/sample-conference-java/gradle/wrapper/gradle-wrapper.properties +++ b/sample-conference-java/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists