├── .DS_Store
├── .gitignore
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── cometchat
│ │ └── pushnotificationsample
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── assets
│ │ └── SampleUsers.json
│ ├── java
│ │ └── com
│ │ │ └── cometchat
│ │ │ └── pushnotificationsample
│ │ │ ├── AppConfig.java
│ │ │ ├── CallConnection.java
│ │ │ ├── CallConnectionService.java
│ │ │ ├── CallEventReceiver.java
│ │ │ ├── CallScreenActivity.java
│ │ │ ├── CometChatNotification.java
│ │ │ ├── ConversationFragment.java
│ │ │ ├── CreateUserActivity.java
│ │ │ ├── HomeScreenActivity.java
│ │ │ ├── LoginActivity.java
│ │ │ ├── MainActivity.java
│ │ │ ├── MessagesFragment.java
│ │ │ ├── PushNotificationService.java
│ │ │ ├── SplashScreenActivity.java
│ │ │ └── helper
│ │ │ ├── AppUtils.java
│ │ │ ├── CometChatObjectCallback.java
│ │ │ ├── CometChatObjectHelper.java
│ │ │ └── ConstantFile.java
│ └── res
│ │ ├── drawable-v24
│ │ └── ic_launcher_foreground.xml
│ │ ├── drawable
│ │ ├── captainamerica.png
│ │ ├── cometchat_white.png
│ │ ├── curved_blue_button.xml
│ │ ├── ic_arrow_right.xml
│ │ ├── ic_arrow_right_selected.xml
│ │ ├── ic_arrow_right_unselected.xml
│ │ ├── ic_launcher_background.xml
│ │ ├── ic_logout.xml
│ │ ├── ironman.png
│ │ ├── spiderman.png
│ │ └── wolverine.png
│ │ ├── layout
│ │ ├── activity_call_screen.xml
│ │ ├── activity_create_user.xml
│ │ ├── activity_home_screen.xml
│ │ ├── activity_login.xml
│ │ ├── activity_main.xml
│ │ ├── activity_splash.xml
│ │ ├── fragment_conversation.xml
│ │ ├── fragment_messages.xml
│ │ └── view_menu.xml
│ │ ├── mipmap-anydpi-v26
│ │ ├── ic_launcher.xml
│ │ └── ic_launcher_round.xml
│ │ ├── mipmap-anydpi-v33
│ │ └── ic_launcher.xml
│ │ ├── mipmap-hdpi
│ │ ├── ic_launcher.webp
│ │ └── ic_launcher_round.webp
│ │ ├── mipmap-mdpi
│ │ ├── ic_launcher.webp
│ │ └── ic_launcher_round.webp
│ │ ├── mipmap-xhdpi
│ │ ├── ic_launcher.webp
│ │ └── ic_launcher_round.webp
│ │ ├── mipmap-xxhdpi
│ │ ├── ic_launcher.webp
│ │ └── ic_launcher_round.webp
│ │ ├── mipmap-xxxhdpi
│ │ ├── ic_launcher.webp
│ │ └── ic_launcher_round.webp
│ │ ├── values-night
│ │ └── themes.xml
│ │ ├── values
│ │ ├── colors.xml
│ │ ├── strings.xml
│ │ └── themes.xml
│ │ └── xml
│ │ ├── backup_rules.xml
│ │ └── data_extraction_rules.xml
│ └── test
│ └── java
│ └── com
│ └── cometchat
│ └── pushnotificationsample
│ └── ExampleUnitTest.java
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cometchat/cometchat-push-notification-app-android/927d97b12da615426de1de15fcba14cad63e1bcf/.DS_Store
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Gradle files
2 | .gradle/
3 | build/
4 |
5 | # Local configuration file (sdk path, etc)
6 | local.properties
7 |
8 | # Log/OS Files
9 | *.log
10 |
11 | # Android Studio generated files and folders
12 | captures/
13 | .externalNativeBuild/
14 | .cxx/
15 | *.apk
16 | output.json
17 |
18 | # IntelliJ
19 | *.iml
20 | .idea/
21 | misc.xml
22 | deploymentTargetDropDown.xml
23 | render.experimental.xml
24 |
25 | # Keystore files
26 | *.jks
27 | *.keystore
28 |
29 | # Google Services (e.g. APIs or Firebase)
30 | app/google-services.json
31 |
32 | # Android Profiling
33 | *.hprof
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | # Android Push Notification Sample App
6 |
7 | The CometChat Android Push Notification Sample App is capable of handling push notifications for one-on-one (private), group messaging, and even call notifications. This sample app enables users to send and receive text messages, make and receive calls, and effectively displays push notifications for these interactions.
8 |
9 | ## 🚀 Try the New v5 UI Kit!
10 | Discover the all-new [v5 UI Kit](https://github.com/cometchat/cometchat-uikit-android/tree/v5), featuring a completely revamped design for enhanced usability and visual appeal. With restructured components, advanced styling options, and a streamlined integration process, v5 offers a seamless, customizable experience tailored to your needs. Try it now and elevate your development workflow!
11 |
12 | The sample app uses Firebase Cloud Messaging (FCM) for delivering push notifications to Android.
13 |
14 | > [!NOTE]
15 | > If you are using Push Notifications (Extension), please refer to our [Android Push Notifications (Extension)](https://github.com/cometchat/cometchat-push-notification-app-android/tree/v4-push-notifications-extension) sample app.
16 |
17 | ## Pre-requisite
18 |
19 | 1. Login to the [CometChat Dashboard](https://app.cometchat.com/).
20 | 2. Select an existing app or create a new one.
21 | 3. Click on the Notifications section from the menu on the left.
22 | 4. Enable Push Notifications by clicking on the toggle bar and configure the push notifications.
23 | 5. Add credentials for FCM.
24 |
25 | ## Run the Sample App
26 |
27 | 1. Clone this repository.
28 | 2. Add your app credentials like `APP_ID`, `REGION`, and `AUTH_KEY` in the `AppConfig.java` file.
29 | 3. Also add the `FCM_PROVIDER_ID` in `AppConfig.java` as that is required while registering push token.
30 | 4. Place the `google-services.json` file in the correct location as per FCM's documentation.
31 | 5. Once the app is running on your device or emulator, login with a user.
32 | 6. Allow the permission to display push notifications.
33 | 7. Put the app in the background or terminate it.
34 | 8. Send a message or call to the logged in user from another device.
35 | 9. You should see a push notification for a message and call notification for a call.
36 | 10. Tap on the notification to open the Sample app for message.
37 | 11. Tap on "Accept" to join an incoming call or tap on "Decline" to reject it.
38 |
39 | ## Help and Support
40 |
41 | For issues running the project or integrating with our UI Kits, consult our [documentation](https://www.cometchat.com/docs/) or create a [support ticket](https://help.cometchat.com/hc/en-us) or seek real-time support via the [CometChat Dashboard](https://app.cometchat.com/).
42 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id 'com.android.application'
3 | id 'com.google.gms.google-services'
4 | }
5 |
6 | android {
7 | namespace 'com.cometchat.pushnotificationsample'
8 | compileSdk 34
9 |
10 | defaultConfig {
11 | applicationId "com.cometchat.pushnotificationsample"
12 | minSdk 24
13 | targetSdk 34
14 | versionCode 2
15 | versionName "1.0.1"
16 |
17 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
18 | manifestPlaceholders = [file_provider: "com.cometchat.pushnotificationsample"]
19 | }
20 |
21 | buildTypes {
22 | release {
23 | minifyEnabled false
24 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
25 | }
26 | }
27 | compileOptions {
28 | sourceCompatibility JavaVersion.VERSION_1_8
29 | targetCompatibility JavaVersion.VERSION_1_8
30 | }
31 | }
32 |
33 | dependencies {
34 |
35 | implementation 'androidx.appcompat:appcompat:1.6.1'
36 | implementation 'com.google.android.material:material:1.11.0'
37 | implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
38 | implementation 'androidx.activity:activity:1.8.0'
39 | testImplementation 'junit:junit:4.13.2'
40 | androidTestImplementation 'androidx.test.ext:junit:1.1.5'
41 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
42 |
43 |
44 | implementation 'com.github.bumptech.glide:glide:4.16.0'
45 |
46 | //Firebase dependencies
47 | implementation platform('com.google.firebase:firebase-bom:32.8.1')
48 | implementation 'com.google.firebase:firebase-analytics-ktx'
49 | implementation 'com.google.firebase:firebase-messaging'
50 | implementation 'com.google.firebase:firebase-core:21.1.1'
51 |
52 | //CometChat Dependencies
53 | implementation 'com.cometchat:chat-uikit-android:4.3.7'
54 | implementation 'com.cometchat:calls-sdk-android:4.0.2'
55 | implementation 'com.cometchat:chat-sdk-android:4.0.6'
56 |
57 |
58 |
59 | implementation("androidx.lifecycle:lifecycle-service:2.7.0")
60 |
61 | }
62 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/cometchat/pushnotificationsample/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.cometchat.pushnotificationsample;
2 |
3 | import android.content.Context;
4 |
5 | import androidx.test.platform.app.InstrumentationRegistry;
6 | import androidx.test.ext.junit.runners.AndroidJUnit4;
7 |
8 | import org.junit.Test;
9 | import org.junit.runner.RunWith;
10 |
11 | import static org.junit.Assert.*;
12 |
13 | /**
14 | * Instrumented test, which will execute on an Android device.
15 | *
16 | * @see Testing documentation
17 | */
18 | @RunWith(AndroidJUnit4.class)
19 | public class ExampleInstrumentedTest {
20 | @Test
21 | public void useAppContext() {
22 | // Context of the app under test.
23 | Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
24 | assertEquals("com.cometchat.pushnotificationsample", appContext.getPackageName());
25 | }
26 | }
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
9 |
10 |
13 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
30 |
33 |
36 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
48 |
51 |
54 |
55 |
58 |
59 |
60 |
61 |
62 |
66 |
67 |
68 |
69 |
70 |
71 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
--------------------------------------------------------------------------------
/app/src/main/assets/SampleUsers.json:
--------------------------------------------------------------------------------
1 | {
2 | "users": [
3 | {
4 | "uid": "superhero1",
5 | "name": "Iron Man",
6 | "avatar": "https://assets.cometchat.io/sampleapp/users/ironman.png"
7 | },
8 | {
9 | "uid": "superhero2",
10 | "name": "Captain America",
11 | "avatar": "https://assets.cometchat.io/sampleapp/users/captainamerica.png"
12 | },
13 | {
14 | "uid": "superhero3",
15 | "name": "Spiderman",
16 | "avatar": "https://assets.cometchat.io/sampleapp/users/spiderman.png"
17 | },
18 | {
19 | "uid": "superhero4",
20 | "name": "Wolverine",
21 | "avatar": "https://assets.cometchat.io/sampleapp/users/wolverine.png"
22 | },
23 | {
24 | "uid": "superhero5",
25 | "name": "Cyclops",
26 | "avatar": "https://assets.cometchat.io/sampleapp/users/cyclops.png"
27 | }
28 | ]
29 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/cometchat/pushnotificationsample/AppConfig.java:
--------------------------------------------------------------------------------
1 | package com.cometchat.pushnotificationsample;
2 |
3 | public class AppConfig {
4 |
5 | public static class AppDetails {
6 |
7 | public static final String APP_ID = "XXXXXXXXXXXXXXXXX";
8 | public static final String AUTH_KEY = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
9 | public static final String REGION = "XX";
10 | public static final String FCM_PROVIDER_ID = "XXXXXXXXXXXXXXXX";
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/app/src/main/java/com/cometchat/pushnotificationsample/CallConnection.java:
--------------------------------------------------------------------------------
1 | package com.cometchat.pushnotificationsample;
2 |
3 | import android.content.Intent;
4 | import android.telecom.CallAudioState;
5 | import android.telecom.Connection;
6 | import android.telecom.DisconnectCause;
7 |
8 | import android.widget.Toast;
9 |
10 | import com.cometchat.chat.constants.CometChatConstants;
11 | import com.cometchat.chat.core.Call;
12 | import com.cometchat.chat.core.CometChat;
13 | import com.cometchat.chat.exceptions.CometChatException;
14 | import com.cometchat.chatuikit.shared.cometchatuikit.CometChatUIKit;
15 | import com.cometchat.chatuikit.shared.cometchatuikit.UIKitSettings;
16 | import com.cometchat.pushnotificationsample.helper.ConstantFile;
17 |
18 | public class CallConnection extends Connection {
19 |
20 | CallConnectionService service;
21 | Call call;
22 |
23 | public CallConnection(CallConnectionService service, Call call) {
24 | this.service = service;
25 | this.call = call;
26 | }
27 |
28 | @Override
29 | public void onCallAudioStateChanged(CallAudioState state) {
30 | }
31 |
32 | @Override
33 | public void onDisconnect() {
34 | super.onDisconnect();
35 | destroyConnection();
36 | setDisconnected(new DisconnectCause(DisconnectCause.LOCAL, ConstantFile.IntentStrings.MISSED));
37 | if (CometChat.getActiveCall() != null)
38 | onDisconnect(CometChat.getActiveCall());
39 | }
40 |
41 | void onDisconnect(Call call) {
42 | CometChat.rejectCall(call.getSessionId(), CometChatConstants.CALL_STATUS_CANCELLED, new CometChat.CallbackListener() {
43 | @Override
44 | public void onSuccess(Call call) {
45 | }
46 |
47 | @Override
48 | public void onError(CometChatException e) {
49 | Toast.makeText(service, R.string.cometchat_disconnect_error, Toast.LENGTH_LONG).show();
50 | }
51 | });
52 | }
53 |
54 | public void destroyConnection() {
55 | setDisconnected(new DisconnectCause(DisconnectCause.REMOTE, ConstantFile.IntentStrings.REJECTED));
56 | super.destroy();
57 | }
58 |
59 | @Override
60 | public void onAnswer(int videoState) {
61 |
62 | if (call.getSessionId() != null) {
63 |
64 | if (!CometChat.isInitialized()) {
65 | initializeCometChat();
66 | }
67 | CometChat.acceptCall(call.getSessionId(), new CometChat.CallbackListener() {
68 | @Override
69 | public void onSuccess(Call call) {
70 | Intent intent = new Intent(service, CallScreenActivity.class);
71 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
72 | intent.putExtra(ConstantFile.IntentStrings.SESSION_ID, call.getSessionId());
73 | intent.putExtra(ConstantFile.IntentStrings.RECEIVER_TYPE, call.getReceiverType());
74 | intent.putExtra(ConstantFile.IntentStrings.CALL_ACTION, call.getAction());
75 | intent.putExtra(ConstantFile.IntentStrings.CALL_TYPE, call.getType());
76 | service.startActivity(intent);
77 | destroyConnection();
78 | }
79 |
80 | @Override
81 | public void onError(CometChatException e) {
82 | destroyConnection();
83 | Toast.makeText(service, R.string.error + e.getMessage(), Toast.LENGTH_LONG).show();
84 | }
85 | });
86 | }
87 | }
88 |
89 | @Override
90 | public void onShowIncomingCallUi() {
91 | }
92 |
93 | @Override
94 | public void onAnswer() {
95 | if (call.getSessionId() != null) {
96 | if (!CometChat.isInitialized()) {
97 | initializeCometChat();
98 | }
99 | CometChat.acceptCall(call.getSessionId(), new CometChat.CallbackListener() {
100 | @Override
101 | public void onSuccess(Call call) {
102 | service.sendBroadcast(getCallIntent());
103 | Intent intent = new Intent(service, CallScreenActivity.class);
104 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
105 | intent.putExtra(ConstantFile.IntentStrings.SESSION_ID, call.getSessionId());
106 | intent.putExtra(ConstantFile.IntentStrings.RECEIVER_TYPE, call.getReceiverType());
107 | intent.putExtra(ConstantFile.IntentStrings.CALL_ACTION, call.getAction());
108 | intent.putExtra(ConstantFile.IntentStrings.CALL_TYPE, call.getType());
109 | service.startActivity(intent);
110 | destroyConnection();
111 | }
112 |
113 | @Override
114 | public void onError(CometChatException e) {
115 | destroyConnection();
116 | Toast.makeText(service, R.string.error + e.getMessage(), Toast.LENGTH_LONG).show();
117 | }
118 | });
119 | }
120 | }
121 |
122 | @Override
123 | public void onHold() {
124 | }
125 |
126 | @Override
127 | public void onUnhold() {
128 | }
129 |
130 | @Override
131 | public void onReject() {
132 | if (call.getSessionId() != null) {
133 | if (!CometChat.isInitialized()) {
134 | initializeCometChat();
135 | }
136 | CometChat.rejectCall(call.getSessionId(), CometChatConstants.CALL_STATUS_REJECTED, new CometChat.CallbackListener() {
137 | @Override
138 | public void onSuccess(Call call) {
139 | destroyConnection();
140 | setDisconnected(new DisconnectCause(DisconnectCause.REJECTED, ConstantFile.IntentStrings.REJECTED));
141 | }
142 |
143 | @Override
144 | public void onError(CometChatException e) {
145 | destroyConnection();
146 | Toast.makeText(service, R.string.error + e.getMessage(), Toast.LENGTH_LONG).show();
147 | }
148 | });
149 | }
150 | }
151 |
152 | private Intent getCallIntent() {
153 | Intent callIntent = new Intent(ConstantFile.IntentStrings.COMETCHAT_CALL_EVENT);
154 | callIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
155 | callIntent.putExtra(ConstantFile.IntentStrings.SESSION_ID, call.getSessionId());
156 | return callIntent;
157 | }
158 |
159 | private void initializeCometChat() {
160 |
161 | UIKitSettings uiKitSettings = new UIKitSettings.UIKitSettingsBuilder()
162 | .setRegion(AppConfig.AppDetails.REGION)
163 | .setAppId(AppConfig.AppDetails.APP_ID)
164 | .setAuthKey(AppConfig.AppDetails.AUTH_KEY)
165 | .subscribePresenceForAllUsers().build();
166 |
167 | CometChatUIKit.init(service, uiKitSettings, new CometChat.CallbackListener() {
168 | @Override
169 | public void onSuccess(String successString) {
170 | }
171 |
172 | @Override
173 | public void onError(CometChatException e) {
174 | }
175 | });
176 | }
177 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/cometchat/pushnotificationsample/CallConnectionService.java:
--------------------------------------------------------------------------------
1 | package com.cometchat.pushnotificationsample;
2 |
3 | import static android.telecom.TelecomManager.PRESENTATION_ALLOWED;
4 |
5 | import android.net.Uri;
6 | import android.os.Build;
7 | import android.os.Bundle;
8 | import android.telecom.Connection;
9 | import android.telecom.ConnectionRequest;
10 | import android.telecom.ConnectionService;
11 | import android.telecom.PhoneAccountHandle;
12 | import android.telecom.TelecomManager;
13 | import android.telecom.VideoProfile;
14 |
15 | import android.view.Surface;
16 | import android.widget.Toast;
17 |
18 | import com.cometchat.chat.core.Call;
19 | import com.cometchat.pushnotificationsample.helper.ConstantFile;
20 |
21 | public class CallConnectionService extends ConnectionService {
22 | public static CallConnection conn;
23 |
24 | public CallConnectionService() {
25 | super();
26 | }
27 |
28 | @Override
29 | public Connection onCreateIncomingConnection(PhoneAccountHandle connectionManagerPhoneAccount, ConnectionRequest request) {
30 | Bundle bundle = request.getExtras();
31 | String sessionID = bundle.getString(ConstantFile.IntentStrings.SESSION_ID);
32 | String name = bundle.getString(ConstantFile.IntentStrings.NAME);
33 | String type = bundle.getString(ConstantFile.IntentStrings.TYPE);
34 | String callType = bundle.getString(ConstantFile.IntentStrings.CALL_TYPE);
35 | callType = callType.substring(0, 1).toUpperCase() + callType.substring(1);
36 | String receiverUID = bundle.getString(ConstantFile.IntentStrings.RECEIVER_ID);
37 | if (receiverUID != null && type != null) {
38 | Call call = new Call(receiverUID, type, callType);
39 | call.setSessionId(sessionID);
40 | conn = new CallConnection(this, call);
41 | }
42 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
43 | conn.setConnectionProperties(Connection.PROPERTY_SELF_MANAGED);
44 | }
45 | conn.setCallerDisplayName(name, PRESENTATION_ALLOWED);
46 | conn.setAddress(Uri.parse(callType + getString(R.string.call)), PRESENTATION_ALLOWED);
47 | conn.setInitializing();
48 | conn.setVideoProvider(new Connection.VideoProvider() {
49 | @Override
50 | public void onSetCamera(String cameraId) {
51 | }
52 |
53 | @Override
54 | public void onSetPreviewSurface(Surface surface) {
55 | }
56 |
57 | @Override
58 | public void onSetDisplaySurface(Surface surface) {
59 | }
60 |
61 | @Override
62 | public void onSetDeviceOrientation(int rotation) {
63 | }
64 |
65 | @Override
66 | public void onSetZoom(float value) {
67 | }
68 |
69 | @Override
70 | public void onSendSessionModifyRequest(VideoProfile fromProfile, VideoProfile toProfile) {
71 | }
72 |
73 | @Override
74 | public void onSendSessionModifyResponse(VideoProfile responseProfile) {
75 |
76 | }
77 |
78 | @Override
79 | public void onRequestCameraCapabilities() {
80 | }
81 |
82 | @Override
83 | public void onRequestConnectionDataUsage() {
84 |
85 | }
86 |
87 | @Override
88 | public void onSetPauseImage(Uri uri) {
89 |
90 | }
91 | });
92 | conn.setActive();
93 | return conn;
94 | }
95 |
96 | @Override
97 | public void onCreateIncomingConnectionFailed(PhoneAccountHandle connectionManagerPhoneAccount, ConnectionRequest request) {
98 | super.onCreateIncomingConnectionFailed(connectionManagerPhoneAccount, request);
99 | }
100 |
101 | @Override
102 | public void onCreateOutgoingConnectionFailed(PhoneAccountHandle connectionManagerPhoneAccount, ConnectionRequest request) {
103 | super.onCreateOutgoingConnectionFailed(connectionManagerPhoneAccount, request);
104 | }
105 |
106 | @Override
107 | public Connection onCreateOutgoingConnection(PhoneAccountHandle connectionManagerPhoneAccount, ConnectionRequest request) {
108 | Bundle bundle = request.getExtras();
109 | String sessionID = bundle.getString(ConstantFile.IntentStrings.SESSION_ID);
110 | String name = bundle.getString(ConstantFile.IntentStrings.NAME);
111 | String receiverType = bundle.getString(ConstantFile.IntentStrings.TYPE);
112 | String callType = bundle.getString(ConstantFile.IntentStrings.CALL_TYPE);
113 | String receiverUID = bundle.getString(ConstantFile.IntentStrings.RECEIVER_ID);
114 |
115 | if (receiverUID != null) {
116 | Call call = new Call(receiverUID, receiverType, callType);
117 | call.setSessionId(sessionID);
118 | conn = new CallConnection(this, call);
119 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
120 | conn.setConnectionProperties(Connection.PROPERTY_SELF_MANAGED);
121 | }
122 | conn.setCallerDisplayName(name, TelecomManager.PRESENTATION_ALLOWED);
123 | conn.setAddress(request.getAddress(), TelecomManager.PRESENTATION_ALLOWED);
124 | conn.setInitializing();
125 | conn.setActive();
126 | return conn;
127 | } else {
128 | String phoneNumber = bundle.getString(ConstantFile.IntentStrings.ORIGINAL_NUMBER);
129 | Toast.makeText(getBaseContext(), R.string.cometchat_tried_calling + phoneNumber, Toast.LENGTH_LONG).show();
130 | return super.onCreateOutgoingConnection(connectionManagerPhoneAccount, request);
131 | }
132 | }
133 | }
134 |
--------------------------------------------------------------------------------
/app/src/main/java/com/cometchat/pushnotificationsample/CallEventReceiver.java:
--------------------------------------------------------------------------------
1 | package com.cometchat.pushnotificationsample;
2 |
3 | import android.content.BroadcastReceiver;
4 | import android.content.Context;
5 | import android.content.Intent;
6 |
7 | public class CallEventReceiver extends BroadcastReceiver {
8 |
9 | @Override
10 | public void onReceive(Context context, Intent intent) {
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/app/src/main/java/com/cometchat/pushnotificationsample/CallScreenActivity.java:
--------------------------------------------------------------------------------
1 | package com.cometchat.pushnotificationsample;
2 |
3 | import androidx.appcompat.app.AppCompatActivity;
4 |
5 | import android.content.Intent;
6 | import android.os.Bundle;
7 |
8 | import com.cometchat.chat.constants.CometChatConstants;
9 | import com.cometchat.chatuikit.calls.ongoingcall.CometChatOngoingCall;
10 | import com.cometchat.pushnotificationsample.helper.ConstantFile;
11 |
12 | public class CallScreenActivity extends AppCompatActivity {
13 | @Override
14 | protected void onCreate(Bundle savedInstanceState) {
15 | super.onCreate(savedInstanceState);
16 | setContentView(R.layout.activity_call_screen);
17 |
18 | CometChatOngoingCall ongoingCall = findViewById(R.id.ongoing_call);
19 |
20 | Intent intent = getIntent();
21 | String sessionID = intent.getStringExtra(ConstantFile.IntentStrings.SESSION_ID);
22 | String receiverType = intent.getStringExtra(ConstantFile.IntentStrings.RECEIVER_TYPE);
23 | String action = intent.getStringExtra(ConstantFile.IntentStrings.CALL_ACTION);
24 | String type = intent.getStringExtra(ConstantFile.IntentStrings.CALL_TYPE);
25 |
26 | if (sessionID != null && receiverType != null && action != null) {
27 |
28 | if (action.equals(CometChatConstants.CALL_STATUS_ONGOING)) {
29 | ongoingCall.setSessionId(sessionID);
30 | ongoingCall.setReceiverType(receiverType);
31 | ongoingCall.setCallType(type);
32 | ongoingCall.startCall();
33 | }
34 | }
35 | }
36 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/cometchat/pushnotificationsample/CometChatNotification.java:
--------------------------------------------------------------------------------
1 | package com.cometchat.pushnotificationsample;
2 |
3 | import static android.content.Context.TELECOM_SERVICE;
4 |
5 | import android.Manifest;
6 |
7 | import android.app.Notification;
8 | import android.app.NotificationChannel;
9 | import android.app.NotificationManager;
10 | import android.app.PendingIntent;
11 | import android.content.ComponentName;
12 | import android.content.Context;
13 | import android.content.Intent;
14 | import android.content.pm.PackageManager;
15 | import android.graphics.Bitmap;
16 | import android.graphics.BitmapFactory;
17 | import android.net.Uri;
18 | import android.os.Build;
19 | import android.os.Bundle;
20 | import android.telecom.PhoneAccount;
21 | import android.telecom.PhoneAccountHandle;
22 | import android.telecom.TelecomManager;
23 | import android.telecom.VideoProfile;
24 | import android.text.TextUtils;
25 | import android.util.Log;
26 |
27 | import androidx.annotation.NonNull;
28 | import androidx.core.app.NotificationCompat;
29 | import androidx.core.content.ContextCompat;
30 |
31 | import com.cometchat.chat.constants.CometChatConstants;
32 | import com.cometchat.chat.core.Call;
33 | import com.cometchat.chat.core.CometChat;
34 | import com.cometchat.chat.core.CometChatNotifications;
35 | import com.cometchat.chat.enums.PushPlatforms;
36 | import com.cometchat.chat.exceptions.CometChatException;
37 | import com.cometchat.chat.models.AppEntity;
38 | import com.cometchat.chat.models.Group;
39 | import com.cometchat.chat.models.User;
40 | import com.cometchat.pushnotificationsample.helper.ConstantFile;
41 | import com.google.android.gms.tasks.OnCompleteListener;
42 | import com.google.android.gms.tasks.Task;
43 | import com.google.firebase.FirebaseApp;
44 | import com.google.firebase.messaging.FirebaseMessaging;
45 | import com.google.firebase.messaging.RemoteMessage;
46 |
47 | import org.json.JSONException;
48 | import org.json.JSONObject;
49 |
50 | import java.io.IOException;
51 | import java.io.InputStream;
52 | import java.net.HttpURLConnection;
53 | import java.net.URL;
54 | import java.util.List;
55 |
56 |
57 | public class CometChatNotification {
58 | private static final String TAG = CometChatNotification.class.getSimpleName();
59 | private static Context context;
60 | private static CometChatNotification cometChatNotification;
61 | private static NotificationManager notificationManager;
62 | private static TelecomManager telecomManager;
63 | private static PhoneAccountHandle phoneAccountHandle;
64 |
65 | private CometChatNotification() {
66 | }
67 |
68 | public static CometChatNotification getInstance(Context c) {
69 | if (cometChatNotification == null) {
70 | cometChatNotification = new CometChatNotification();
71 | context = c;
72 | notificationManager = (NotificationManager) c.getSystemService(Context.NOTIFICATION_SERVICE);
73 |
74 | //For VoIP
75 | telecomManager = (TelecomManager) context.getSystemService(TELECOM_SERVICE);
76 | ComponentName componentName = new ComponentName(context, CallConnectionService.class);
77 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
78 | phoneAccountHandle = new PhoneAccountHandle(componentName, context.getPackageName());
79 | PhoneAccount phoneAccount = PhoneAccount.builder(phoneAccountHandle, context.getPackageName()).setCapabilities(PhoneAccount.CAPABILITY_CALL_PROVIDER).build();
80 | telecomManager.registerPhoneAccount(phoneAccount);
81 | }
82 | }
83 | return cometChatNotification;
84 | }
85 |
86 |
87 | public void registerCometChatNotification(final CometChat.CallbackListener listener) {
88 | if (!isFirebaseAppInitialized()) {
89 | listener.onError(new CometChatException(ConstantFile.ErrorStrings.NOTIFICATION_NOT_REGISTERED, ConstantFile.ErrorStrings.FIREBASE_NOT_REGISTERED));
90 | return;
91 | }
92 |
93 | FirebaseMessaging.getInstance().getToken().addOnCompleteListener(new OnCompleteListener() {
94 | @Override
95 | public void onComplete(@NonNull Task task) {
96 | if (!task.isSuccessful()) {
97 | Log.e(TAG, context.getString(R.string.cometchat_fcmtoken_failed), task.getException());
98 | return;
99 | }
100 | String token = task.getResult();
101 | Log.i(TAG, "Push Notification Token = " + token);
102 | CometChatNotifications.registerPushToken(token, PushPlatforms.FCM_ANDROID, AppConfig.AppDetails.FCM_PROVIDER_ID, new CometChat.CallbackListener() {
103 | @Override
104 | public void onSuccess(String s) {
105 | listener.onSuccess(s);
106 | }
107 |
108 | @Override
109 | public void onError(CometChatException e) {
110 | listener.onError(e);
111 | }
112 | });
113 | }
114 | });
115 | }
116 |
117 | public void renderCometChatNotification(RemoteMessage remoteMessage, final CometChat.CallbackListener listener) {
118 | JSONObject data = new JSONObject(remoteMessage.getData());
119 |
120 | try {
121 | switch (data.getString(ConstantFile.IntentStrings.TYPE)) {
122 | case ConstantFile.IntentStrings.CHAT:
123 | renderTextMessageNotification(data);
124 | break;
125 |
126 | case CometChatConstants.CATEGORY_CALL:
127 | handleCallNotification(data);
128 | break;
129 | default:
130 | }
131 |
132 |
133 | } catch (JSONException e) {
134 | e.printStackTrace();
135 | }
136 | }
137 |
138 | private void handleCallNotification(JSONObject data) {
139 |
140 | try {
141 | long callTime = Long.parseLong(data.getString(ConstantFile.IntentStrings.SENT_AT));
142 | if (data.getString(ConstantFile.IntentStrings.CALL_ACTION).equals(CometChatConstants.CALL_STATUS_INITIATED) && System.currentTimeMillis() <= (callTime + 30000)) {
143 | Call call = new Call(data.getString(ConstantFile.IntentStrings.RECEIVER), data.getString(ConstantFile.IntentStrings.RECEIVER_TYPE), data.getString(ConstantFile.IntentStrings.CALL_TYPE));
144 | call.setSessionId(data.getString(ConstantFile.IntentStrings.SESSION_ID));
145 | if (data.getString(ConstantFile.IntentStrings.RECEIVER_TYPE).equals(CometChatConstants.RECEIVER_TYPE_USER)) {
146 | User user = new User();
147 | user.setUid(data.getString(ConstantFile.IntentStrings.RECEIVER));
148 | user.setName(data.getString(ConstantFile.IntentStrings.RECEIVER_NAME));
149 | user.setAvatar(data.getString(ConstantFile.IntentStrings.RECEIVER_AVATAR));
150 | call.setCallInitiator(user);
151 | call.setCallReceiver(user);
152 | } else {
153 | Group group = new Group();
154 | group.setGuid(data.getString(ConstantFile.IntentStrings.RECEIVER));
155 | group.setName(data.getString(ConstantFile.IntentStrings.RECEIVER_NAME));
156 | group.setIcon(data.getString(ConstantFile.IntentStrings.RECEIVER_AVATAR));
157 | call.setCallInitiator(group);
158 | call.setCallReceiver(group);
159 | }
160 | startIncomingCall(call);
161 | } else {
162 | if (ContextCompat.checkSelfPermission(context, Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED && telecomManager != null) {
163 | boolean isInCall = telecomManager.isInCall();
164 | if (isInCall) {
165 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
166 | telecomManager.endCall();
167 | }
168 | }
169 | }
170 | }
171 | } catch (JSONException e) {
172 | throw new RuntimeException(e);
173 | }
174 | }
175 |
176 |
177 | public void startIncomingCall(Call call) {
178 | AppEntity entity = call.getCallInitiator();
179 |
180 | if (context.checkSelfPermission(Manifest.permission.MANAGE_OWN_CALLS) == PackageManager.PERMISSION_GRANTED) {
181 | Bundle extras = new Bundle();
182 | Uri uri = Uri.fromParts(PhoneAccount.SCHEME_TEL, call.getSessionId().substring(0, 11), null);
183 |
184 | extras.putString(ConstantFile.IntentStrings.SESSION_ID, call.getSessionId());
185 | extras.putString(ConstantFile.IntentStrings.TYPE, call.getReceiverType());
186 | extras.putString(ConstantFile.IntentStrings.CALL_TYPE, call.getType());
187 |
188 | if (entity instanceof User) {
189 | extras.putString(ConstantFile.IntentStrings.NAME, ((User) entity).getName());
190 | } else {
191 | extras.putString(ConstantFile.IntentStrings.NAME, ((Group) entity).getName());
192 | }
193 |
194 | if (entity instanceof User) {
195 | extras.putString(ConstantFile.IntentStrings.ID, ((User) entity).getUid());
196 | } else {
197 | extras.putString(ConstantFile.IntentStrings.ID, ((Group) entity).getGuid());
198 | }
199 |
200 | if (call.getType().equalsIgnoreCase(CometChatConstants.CALL_TYPE_VIDEO)) {
201 | extras.putInt(TelecomManager.EXTRA_INCOMING_VIDEO_STATE, VideoProfile.STATE_BIDIRECTIONAL);
202 | } else {
203 | extras.putInt(TelecomManager.EXTRA_INCOMING_VIDEO_STATE, VideoProfile.STATE_AUDIO_ONLY);
204 | }
205 |
206 | extras.putParcelable(TelecomManager.EXTRA_INCOMING_CALL_ADDRESS, uri);
207 | extras.putParcelable(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE, phoneAccountHandle);
208 | extras.putBoolean(TelecomManager.EXTRA_START_CALL_WITH_SPEAKERPHONE, true);
209 | try {
210 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
211 | telecomManager.isIncomingCallPermitted(phoneAccountHandle);
212 | }
213 | telecomManager.addNewIncomingCall(phoneAccountHandle, extras);
214 | } catch (SecurityException e) {
215 | e.printStackTrace();
216 | } catch (Exception e) {
217 | }
218 | }
219 | }
220 |
221 | private void renderTextMessageNotification(JSONObject message) {
222 | try {
223 | if (message.getString(ConstantFile.IntentStrings.RECEIVER_TYPE).equals(CometChatConstants.RECEIVER_TYPE_USER)) {
224 |
225 | if (message.has(ConstantFile.IntentStrings.SENDER_AVATAR)) {
226 | showNotification(message.getInt(ConstantFile.IntentStrings.TAG), message.getString(ConstantFile.IntentStrings.SENDER_NAME), message.getString(ConstantFile.IntentStrings.BODY), message.getString(ConstantFile.IntentStrings.SENDER_AVATAR), message);
227 | } else {
228 | showNotification(message.getInt(ConstantFile.IntentStrings.TAG), message.getString(ConstantFile.IntentStrings.SENDER_NAME), message.getString(ConstantFile.IntentStrings.BODY), "", message);
229 | }
230 | } else {
231 | if (message.has(ConstantFile.IntentStrings.SENDER_AVATAR)) {
232 | showNotification(message.getInt(ConstantFile.IntentStrings.TAG), message.getString(ConstantFile.IntentStrings.RECEIVER_NAME), message.getString(ConstantFile.IntentStrings.BODY), message.getString(ConstantFile.IntentStrings.SENDER_AVATAR), message);
233 | } else {
234 | showNotification(message.getInt(ConstantFile.IntentStrings.TAG), message.getString(ConstantFile.IntentStrings.RECEIVER_NAME), message.getString(ConstantFile.IntentStrings.BODY), "", message);
235 | }
236 | }
237 | } catch (JSONException e) {
238 | throw new RuntimeException(e);
239 | }
240 |
241 | }
242 |
243 | public boolean checkAccountConnection(Context context) {
244 | boolean isConnected = false;
245 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
246 | if (ContextCompat.checkSelfPermission(context, Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED && telecomManager != null) {
247 | final List enabledAccounts = telecomManager.getCallCapablePhoneAccounts();
248 | for (PhoneAccountHandle account : enabledAccounts) {
249 | if (account.getComponentName().getClassName().equals(CallConnectionService.class.getCanonicalName())) {
250 | isConnected = true;
251 | break;
252 | }
253 | }
254 | }
255 | }
256 | return isConnected;
257 | }
258 |
259 | private void showNotification(int nid, String title, String text, String largeIconUrl, JSONObject payload) {
260 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
261 | NotificationChannel channel = new NotificationChannel(ConstantFile.IntentStrings.MESSAGES, title, NotificationManager.IMPORTANCE_DEFAULT);
262 | channel.setDescription("Your messages!!");
263 |
264 | NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
265 | notificationManager.createNotificationChannel(channel);
266 | }
267 | NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
268 | NotificationCompat.Builder builder = new NotificationCompat.Builder(context, ConstantFile.IntentStrings.MESSAGES);
269 | builder.setContentTitle(title);
270 | builder.setContentText(text);
271 | builder.setPriority(NotificationCompat.PRIORITY_MAX);
272 | builder.setSmallIcon(R.drawable.ic_launcher_foreground);
273 | builder.setAutoCancel(true);
274 |
275 | if (!TextUtils.isEmpty(largeIconUrl)) {
276 | builder.setLargeIcon(getBitmapFromURL(largeIconUrl));
277 | } else {
278 | builder.setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_launcher_background));
279 | }
280 |
281 | Intent intent = new Intent(context, HomeScreenActivity.class);
282 |
283 | intent.putExtra(ConstantFile.IntentStrings.NOTIFICATION_PAYLOAD, payload.toString());
284 | PendingIntent pendingIntent = PendingIntent.getActivity(context, 501, intent, PendingIntent.FLAG_MUTABLE | PendingIntent.FLAG_UPDATE_CURRENT);
285 | builder.setContentIntent(pendingIntent);
286 |
287 | Notification notification = builder.build();
288 | notificationManager.notify(nid, notification);
289 | }
290 |
291 | private static boolean isFirebaseAppInitialized() {
292 | return !FirebaseApp.getApps(context).isEmpty();
293 | }
294 |
295 | private Bitmap getBitmapFromURL(String strURL) {
296 | if (strURL != null) {
297 | try {
298 | URL url = new URL(strURL);
299 | HttpURLConnection connection = (HttpURLConnection) url.openConnection();
300 | connection.setDoInput(true);
301 | connection.connect();
302 | InputStream input = connection.getInputStream();
303 | return BitmapFactory.decodeStream(input);
304 | } catch (IOException e) {
305 | e.printStackTrace();
306 | return null;
307 | }
308 | } else {
309 | return null;
310 | }
311 | }
312 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/cometchat/pushnotificationsample/ConversationFragment.java:
--------------------------------------------------------------------------------
1 | package com.cometchat.pushnotificationsample;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 |
6 | import androidx.fragment.app.Fragment;
7 |
8 | import android.view.LayoutInflater;
9 | import android.view.View;
10 | import android.view.ViewGroup;
11 | import android.widget.ImageView;
12 |
13 | import com.cometchat.chat.core.CometChat;
14 | import com.cometchat.chat.core.CometChatNotifications;
15 | import com.cometchat.chat.exceptions.CometChatException;
16 | import com.cometchat.chatuikit.conversationswithmessages.CometChatConversationsWithMessages;
17 |
18 | public class ConversationFragment extends Fragment {
19 |
20 | @Override
21 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
22 | View view = inflater.inflate(R.layout.fragment_conversation, container, false);
23 |
24 | CometChatConversationsWithMessages conversationWithMessages = view.findViewById(R.id.conversationWithMessages);
25 | View menu = getLayoutInflater().inflate(R.layout.view_menu, null);
26 | ImageView logout = menu.findViewById(R.id.img_logout);
27 | logout.setOnClickListener(v -> {
28 | CometChatNotifications.unregisterPushToken(new CometChat.CallbackListener() {
29 | @Override
30 | public void onSuccess(String s) {
31 | }
32 |
33 | @Override
34 | public void onError(CometChatException e) {
35 | }
36 | });
37 | CometChat.logout(new CometChat.CallbackListener() {
38 | @Override
39 | public void onSuccess(String s) {
40 | Intent i = getActivity().getBaseContext().getPackageManager().getLaunchIntentForPackage(getActivity().getBaseContext().getPackageName());
41 | i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
42 | startActivity(i);
43 | }
44 |
45 | @Override
46 | public void onError(CometChatException e) {
47 | }
48 | });
49 | });
50 | conversationWithMessages.setMenu(menu);
51 | return view;
52 | }
53 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/cometchat/pushnotificationsample/CreateUserActivity.java:
--------------------------------------------------------------------------------
1 | package com.cometchat.pushnotificationsample;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.view.View;
6 | import android.widget.ProgressBar;
7 | import android.widget.RelativeLayout;
8 | import android.widget.Toast;
9 |
10 | import androidx.appcompat.app.AppCompatActivity;
11 | import androidx.appcompat.widget.AppCompatButton;
12 |
13 | import com.cometchat.chatuikit.shared.cometchatuikit.CometChatUIKit;
14 | import com.cometchat.chat.core.CometChat;
15 | import com.cometchat.chat.exceptions.CometChatException;
16 | import com.cometchat.chat.models.User;
17 | import com.google.android.material.snackbar.Snackbar;
18 | import com.google.android.material.textfield.TextInputEditText;
19 |
20 | public class CreateUserActivity extends AppCompatActivity {
21 | private TextInputEditText uid;
22 | private TextInputEditText name;
23 | private AppCompatButton createUserBtn;
24 | private ProgressBar progressBar;
25 |
26 | private RelativeLayout parentView;
27 |
28 | @Override
29 | protected void onCreate(Bundle savedInstanceState) {
30 | super.onCreate(savedInstanceState);
31 | setContentView(R.layout.activity_create_user);
32 | parentView = findViewById(R.id.parent_view);
33 | progressBar = findViewById(R.id.createUserPb);
34 | uid = findViewById(R.id.etUID);
35 | name = findViewById(R.id.etName);
36 | createUserBtn = findViewById(R.id.createUserBtn);
37 | createUserBtn.setTextColor(getResources().getColor(R.color.white));
38 | createUserBtn.setOnClickListener(v -> {
39 | if (uid.getText().toString().isEmpty())
40 | uid.setError(getResources().getString(R.string.fill_this_field));
41 | else if (name.getText().toString().isEmpty())
42 | name.setError(getResources().getString(R.string.fill_this_field));
43 | else {
44 | progressBar.setVisibility(View.VISIBLE);
45 | createUserBtn.setClickable(false);
46 | User user = new User();
47 | user.setUid(uid.getText().toString());
48 | user.setName(name.getText().toString());
49 | CometChatUIKit.createUser(user, new CometChat.CallbackListener() {
50 | @Override
51 | public void onSuccess(User user) {
52 | login(user);
53 | }
54 |
55 | @Override
56 | public void onError(CometChatException e) {
57 | createUserBtn.setClickable(true);
58 | Toast.makeText(CreateUserActivity.this, "Failed to create user", Toast.LENGTH_LONG).show();
59 | }
60 | });
61 | }
62 | });
63 | }
64 |
65 | private void login(User user) {
66 | CometChatUIKit.login(user.getUid(), new CometChat.CallbackListener() {
67 | @Override
68 | public void onSuccess(User user) {
69 | startActivity(new Intent(CreateUserActivity.this, HomeScreenActivity.class));
70 | finishAffinity();
71 | }
72 |
73 | @Override
74 | public void onError(CometChatException e) {
75 | if (uid != null)
76 | Snackbar.make(uid.getRootView(), "Unable to login", Snackbar.LENGTH_INDEFINITE).setAction("Try Again", new View.OnClickListener() {
77 | @Override
78 | public void onClick(View v) {
79 | startActivity(new Intent(CreateUserActivity.this, LoginActivity.class));
80 | }
81 | }).show();
82 | }
83 | });
84 | }
85 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/cometchat/pushnotificationsample/HomeScreenActivity.java:
--------------------------------------------------------------------------------
1 | package com.cometchat.pushnotificationsample;
2 |
3 | import android.Manifest;
4 | import android.app.AlertDialog;
5 | import android.content.ComponentName;
6 | import android.content.Context;
7 | import android.content.Intent;
8 |
9 | import android.os.Bundle;
10 | import android.telecom.TelecomManager;
11 | import android.util.Log;
12 | import android.widget.RelativeLayout;
13 |
14 |
15 | import androidx.annotation.NonNull;
16 | import androidx.annotation.Nullable;
17 | import androidx.appcompat.app.AppCompatActivity;
18 | import androidx.core.app.ActivityCompat;
19 | import androidx.fragment.app.Fragment;
20 |
21 | import com.cometchat.chat.core.CometChat;
22 | import com.cometchat.chat.core.CometChatNotifications;
23 | import com.cometchat.chat.enums.PushPlatforms;
24 | import com.cometchat.chat.exceptions.CometChatException;
25 | import com.cometchat.chat.models.Group;
26 | import com.cometchat.chat.models.User;
27 | import com.cometchat.chatuikit.shared.cometchatuikit.CometChatUIKit;
28 | import com.cometchat.chatuikit.shared.cometchatuikit.CometChatUIKitHelper;
29 | import com.cometchat.chatuikit.shared.cometchatuikit.UIKitSettings;
30 | import com.cometchat.chatuikit.shared.resources.theme.Palette;
31 | import com.cometchat.pushnotificationsample.helper.CometChatObjectCallback;
32 | import com.cometchat.pushnotificationsample.helper.CometChatObjectHelper;
33 | import com.google.android.gms.tasks.OnCompleteListener;
34 | import com.google.android.gms.tasks.Task;
35 | import com.google.firebase.messaging.FirebaseMessaging;
36 |
37 | public class HomeScreenActivity extends AppCompatActivity {
38 |
39 | private final String TAG = HomeScreenActivity.class.getSimpleName();
40 | private RelativeLayout conversationParentView;
41 |
42 | private final int PERMISSION_REQUEST_CODE = 99;
43 |
44 | CometChatNotification cometChatNotification;
45 |
46 | private final String[] permissions = new String[]{Manifest.permission.RECORD_AUDIO, Manifest.permission.CAMERA, Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.ANSWER_PHONE_CALLS, Manifest.permission.CALL_PHONE, Manifest.permission.MANAGE_OWN_CALLS, Manifest.permission.READ_PHONE_STATE, Manifest.permission.POST_NOTIFICATIONS};
47 |
48 | @Override
49 | protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
50 | super.onActivityResult(requestCode, resultCode, data);
51 | }
52 |
53 | @Override
54 | protected void onCreate(Bundle savedInstanceState) {
55 | super.onCreate(savedInstanceState);
56 | setContentView(R.layout.activity_home_screen);
57 | conversationParentView = findViewById(R.id.conversation_container);
58 | cometChatNotification = CometChatNotification.getInstance(this);
59 | setTheme();
60 | handleIntent(getIntent());
61 | loadFragment(new ConversationFragment());
62 | requestPermissions();
63 | FirebaseMessaging.getInstance().getToken().addOnCompleteListener(new OnCompleteListener() {
64 | @Override
65 | public void onComplete(@NonNull Task task) {
66 | if (task.isSuccessful()) {
67 | String pushToken = task.getResult();
68 | CometChatNotifications.registerPushToken(pushToken, PushPlatforms.FCM_ANDROID, AppConfig.AppDetails.FCM_PROVIDER_ID, new CometChat.CallbackListener() {
69 | @Override
70 | public void onSuccess(String s) {
71 | Log.v(TAG, "onSuccess: CometChat Notification Registered : " + s);
72 | }
73 |
74 | @Override
75 | public void onError(CometChatException e) {
76 | }
77 | });
78 | }
79 | }
80 | });
81 | }
82 |
83 | @Override
84 | public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
85 | super.onRequestPermissionsResult(requestCode, permissions, grantResults);
86 | }
87 |
88 | private void requestPermissions() {
89 | //Required Permission
90 | requestPermissions(permissions, PERMISSION_REQUEST_CODE);
91 | ActivityCompat.requestPermissions(this, permissions, PERMISSION_REQUEST_CODE);
92 |
93 | //For VOIP
94 | if (!cometChatNotification.checkAccountConnection(this)) {
95 | AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);
96 | alertDialog.setTitle(R.string.cometchat_VoIP_permission);
97 | alertDialog.setMessage(R.string.cometchat_VoIP_message);
98 | alertDialog.setPositiveButton(R.string.cometchat_VoIP_openSettings, (dialog, which) -> launchVoIPSetting(HomeScreenActivity.this));
99 | alertDialog.setNegativeButton(R.string.cometchat_VoIP_cancel, (dialog, which) -> dialog.dismiss());
100 | alertDialog.create().show();
101 | }
102 | }
103 |
104 | public void launchVoIPSetting(Context context) {
105 | Intent intent = new Intent();
106 | intent.setAction(TelecomManager.ACTION_CHANGE_PHONE_ACCOUNTS);
107 | ComponentName telecomComponent = new ComponentName(getString(R.string.cometchat_android_telecom_package), getString(R.string.cometchat_android_telecom_package_class));
108 | intent.setComponent(telecomComponent);
109 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
110 | context.startActivity(intent);
111 | }
112 |
113 | private void handleIntent(Intent intent) {
114 |
115 | if (!CometChat.isInitialized()) {
116 |
117 | UIKitSettings uiKitSettings = new UIKitSettings.UIKitSettingsBuilder().setRegion(AppConfig.AppDetails.REGION).setAppId(AppConfig.AppDetails.APP_ID).setAuthKey(AppConfig.AppDetails.AUTH_KEY).subscribePresenceForAllUsers().build();
118 |
119 | CometChatUIKit.init(this, uiKitSettings, new CometChat.CallbackListener() {
120 | @Override
121 | public void onSuccess(String successString) {
122 | }
123 |
124 | @Override
125 | public void onError(CometChatException e) {
126 | }
127 | });
128 | }
129 | CometChatObjectHelper.process(intent, new CometChatObjectCallback() {
130 | @Override
131 | public void onUserMessage(User user) {
132 | CometChatUIKitHelper.onOpenChat(user, null);
133 | }
134 |
135 | @Override
136 | public void onGroupMessage(Group group) {
137 | CometChatUIKitHelper.onOpenChat(null, group);
138 | }
139 |
140 | @Override
141 | public void onCallMessage() {
142 | }
143 |
144 | @Override
145 | public void onNoMessage() {
146 | loadFragment(new ConversationFragment());
147 | }
148 | });
149 | }
150 |
151 | private void setTheme() {
152 | Palette palette = Palette.getInstance(this);
153 | palette.primary(getResources().getColor(R.color.colorPrimary, getTheme()));
154 | palette.secondary(getResources().getColor(R.color.colorSecondary, getTheme()));
155 | }
156 |
157 | private void loadFragment(Fragment fragment) {
158 | getSupportFragmentManager().beginTransaction().replace(R.id.conversation_container, fragment).commit();
159 | }
160 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/cometchat/pushnotificationsample/LoginActivity.java:
--------------------------------------------------------------------------------
1 | package com.cometchat.pushnotificationsample;
2 |
3 | import androidx.appcompat.app.AppCompatActivity;
4 |
5 | import android.content.Intent;
6 | import android.os.Bundle;
7 | import android.view.View;
8 | import android.view.inputmethod.EditorInfo;
9 | import android.widget.ProgressBar;
10 | import android.widget.RelativeLayout;
11 | import android.widget.Toast;
12 |
13 | import com.cometchat.chat.core.CometChat;
14 | import com.cometchat.chat.exceptions.CometChatException;
15 | import com.cometchat.chat.models.User;
16 | import com.cometchat.chatuikit.shared.cometchatuikit.CometChatUIKit;
17 | import com.cometchat.chatuikit.shared.cometchatuikit.UIKitSettings;
18 | import com.google.android.material.textfield.TextInputEditText;
19 | import com.google.android.material.textfield.TextInputLayout;
20 |
21 | import java.util.Objects;
22 |
23 | public class LoginActivity extends AppCompatActivity {
24 |
25 | private TextInputLayout inputLayout;
26 | private ProgressBar progressBar;
27 | private TextInputEditText uid;
28 |
29 | @Override
30 | protected void onCreate(Bundle savedInstanceState) {
31 | super.onCreate(savedInstanceState);
32 | setContentView(R.layout.activity_login);
33 |
34 | initCometChatUIKit();
35 | initViews();
36 | }
37 |
38 | private void initViews() {
39 | uid = findViewById(R.id.etUID);
40 | progressBar = findViewById(R.id.loginProgress);
41 | inputLayout = findViewById(R.id.inputUID);
42 |
43 | uid.setOnEditorActionListener((textView, i, keyEvent) -> {
44 | if (i == EditorInfo.IME_ACTION_DONE) {
45 | if (uid.getText().toString().isEmpty()) {
46 | uid.setError("Enter UID");
47 | } else {
48 | uid.setError(null);
49 | progressBar.setVisibility(View.VISIBLE);
50 | inputLayout.setEndIconVisible(false);
51 | login(uid.getText().toString());
52 | }
53 | }
54 | return true;
55 | });
56 |
57 |
58 | findViewById(R.id.tvSignIn).setOnClickListener(view -> {
59 | if (uid.getText().toString().isEmpty()) {
60 | uid.setError("Enter UID");
61 | } else {
62 | findViewById(R.id.loginProgress).setVisibility(View.VISIBLE);
63 | inputLayout.setEndIconVisible(false);
64 | login(uid.getText().toString());
65 | }
66 | });
67 | }
68 |
69 | private void login(String uid) {
70 | CometChatUIKit.login(uid, new CometChat.CallbackListener() {
71 | @Override
72 | public void onSuccess(User user) {
73 | CometChatNotification.getInstance(LoginActivity.this).registerCometChatNotification(new CometChat.CallbackListener() {
74 | @Override
75 | public void onSuccess(String s) {
76 | progressBar.setVisibility(View.GONE);
77 | startActivity(new Intent(LoginActivity.this, HomeScreenActivity.class));
78 | finishAffinity();
79 | }
80 |
81 | @Override
82 | public void onError(CometChatException e) {
83 | }
84 | });
85 | }
86 |
87 | @Override
88 | public void onError(CometChatException e) {
89 | }
90 | });
91 | }
92 |
93 | public void createUser(View view) {
94 | startActivity(new Intent(LoginActivity.this, CreateUserActivity.class));
95 | }
96 | private void initCometChatUIKit() {
97 | UIKitSettings uiKitSettings = new UIKitSettings.UIKitSettingsBuilder().setRegion(AppConfig.AppDetails.REGION).setAppId(AppConfig.AppDetails.APP_ID).setAuthKey(AppConfig.AppDetails.AUTH_KEY).subscribePresenceForAllUsers().build();
98 |
99 | CometChatUIKit.init(this, uiKitSettings, new CometChat.CallbackListener() {
100 | @Override
101 | public void onSuccess(String successString) {
102 | }
103 |
104 | @Override
105 | public void onError(CometChatException e) {
106 | }
107 | });
108 | }
109 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/cometchat/pushnotificationsample/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.cometchat.pushnotificationsample;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.view.View;
6 | import android.widget.ImageView;
7 | import android.widget.LinearLayout;
8 | import android.widget.ProgressBar;
9 | import android.widget.TextView;
10 | import android.widget.Toast;
11 |
12 | import androidx.activity.EdgeToEdge;
13 | import androidx.appcompat.app.AppCompatActivity;
14 | import androidx.appcompat.widget.AppCompatImageView;
15 | import androidx.appcompat.widget.AppCompatTextView;
16 | import androidx.core.graphics.Insets;
17 | import androidx.core.view.ViewCompat;
18 | import androidx.core.view.WindowInsetsCompat;
19 |
20 | import com.bumptech.glide.Glide;
21 | import com.cometchat.chat.core.CometChat;
22 | import com.cometchat.chat.exceptions.CometChatException;
23 | import com.cometchat.chat.models.User;
24 | import com.cometchat.chatuikit.shared.cometchatuikit.CometChatUIKit;
25 | import com.cometchat.pushnotificationsample.helper.AppUtils;
26 | import com.google.android.material.card.MaterialCardView;
27 |
28 | import java.util.List;
29 |
30 | public class MainActivity extends AppCompatActivity {
31 | private MaterialCardView user1;
32 |
33 | private MaterialCardView user2;
34 |
35 | private MaterialCardView user3;
36 |
37 | private MaterialCardView user4;
38 |
39 | private AppCompatImageView ivLogo;
40 | private ProgressBar progressBar;
41 | private AppCompatTextView tvCometChat;
42 | private LinearLayout parentView;
43 | private LinearLayout gridLayoutContainer;
44 | private TextView stateMessage;
45 | private LinearLayout stateLayout;
46 | private TextView user1Name, user2Name, user3Name, user4Name;
47 | private ImageView user1Avatar, user2Avatar, user3Avatar, user4Avatar;
48 |
49 | @Override
50 | protected void onCreate(Bundle savedInstanceState) {
51 | super.onCreate(savedInstanceState);
52 | setContentView(R.layout.activity_main);
53 | parentView = findViewById(R.id.parent_view);
54 | progressBar = findViewById(R.id.progress_bar);
55 | stateMessage = findViewById(R.id.state_message);
56 | stateLayout = findViewById(R.id.state_layout);
57 | gridLayoutContainer = findViewById(R.id.grid_layout_container);
58 | user1 = findViewById(R.id.user1);
59 | user2 = findViewById(R.id.user2);
60 | user3 = findViewById(R.id.user3);
61 | user4 = findViewById(R.id.user4);
62 | ivLogo = findViewById(R.id.ivLogo);
63 | tvCometChat = findViewById(R.id.tvComet);
64 | user1Name = findViewById(R.id.user1_name);
65 | user2Name = findViewById(R.id.user2_name);
66 | user3Name = findViewById(R.id.user3_name);
67 | user4Name = findViewById(R.id.user4_name);
68 | user1Avatar = findViewById(R.id.user1_avatar_image);
69 | user2Avatar = findViewById(R.id.user2_avatar_image);
70 | user3Avatar = findViewById(R.id.user3_avatar_image);
71 | user4Avatar = findViewById(R.id.user4_avatar_image);
72 |
73 | user1.setVisibility(View.GONE);
74 | user2.setVisibility(View.GONE);
75 | user3.setVisibility(View.GONE);
76 | user4.setVisibility(View.GONE);
77 |
78 | gridLayoutContainer.setVisibility(View.INVISIBLE);
79 | stateMessage.setText(R.string.please_wait);
80 | progressBar.setVisibility(View.VISIBLE);
81 | AppUtils.fetchSampleUsers(new CometChat.CallbackListener>() {
82 | @Override
83 | public void onSuccess(List users) {
84 | if (!users.isEmpty()) {
85 | setUsers(users);
86 | } else {
87 | stateLayout.setVisibility(View.VISIBLE);
88 | progressBar.setVisibility(View.GONE);
89 | stateMessage.setText(R.string.no_sample_users_available);
90 | }
91 | }
92 |
93 | @Override
94 | public void onError(CometChatException e) {
95 | setUsers(AppUtils.processSampleUserList(AppUtils.loadJSONFromAsset(MainActivity.this)));
96 | }
97 | });
98 | findViewById(R.id.login).setOnClickListener(view -> startActivity(new Intent(MainActivity.this, LoginActivity.class)));
99 |
100 | user1.setOnClickListener(view -> {
101 | findViewById(R.id.user1Progressbar).setVisibility(View.VISIBLE);
102 | login(user1.getTag().toString());
103 | });
104 | user2.setOnClickListener(view -> {
105 | findViewById(R.id.user2Progressbar).setVisibility(View.VISIBLE);
106 | login(user2.getTag().toString());
107 | });
108 | user3.setOnClickListener(view -> {
109 | findViewById(R.id.user3Progressbar).setVisibility(View.VISIBLE);
110 | login(user3.getTag().toString());
111 | });
112 | user4.setOnClickListener(view -> {
113 | findViewById(R.id.user4Progressbar).setVisibility(View.VISIBLE);
114 | login(user4.getTag().toString());
115 | });
116 | }
117 |
118 | private void setUsers(List users) {
119 | progressBar.setVisibility(View.GONE);
120 | stateLayout.setVisibility(View.GONE);
121 | gridLayoutContainer.setVisibility(View.VISIBLE);
122 | for (int i = 0; i < users.size(); i++) {
123 | if (i == 0) {
124 | user1Name.setText(users.get(i).getName());
125 | Glide.with(this).load(users.get(i).getAvatar()).error(R.drawable.ironman).into(user1Avatar);
126 | user1.setTag(users.get(i).getUid());
127 | user1.setVisibility(View.VISIBLE);
128 | } else if (i == 1) {
129 | user2Name.setText(users.get(i).getName());
130 | Glide.with(this).load(users.get(i).getAvatar()).error(R.drawable.captainamerica).into(user2Avatar);
131 | user2.setTag(users.get(i).getUid());
132 | user2.setVisibility(View.VISIBLE);
133 | } else if (i == 2) {
134 | user3Name.setText(users.get(i).getName());
135 | Glide.with(this).load(users.get(i).getAvatar()).error(R.drawable.spiderman).into(user3Avatar);
136 | user3.setTag(users.get(i).getUid());
137 | user3.setVisibility(View.VISIBLE);
138 | } else if (i == 3) {
139 | user4Name.setText(users.get(i).getName());
140 | Glide.with(this).load(users.get(i).getAvatar()).error(R.drawable.wolverine).into(user4Avatar);
141 | user4.setTag(users.get(i).getUid());
142 | user4.setVisibility(View.VISIBLE);
143 | }
144 | }
145 | }
146 |
147 | private void login(String uid) {
148 | CometChatUIKit.login(uid, new CometChat.CallbackListener() {
149 | @Override
150 | public void onSuccess(User user) {
151 | startActivity(new Intent(MainActivity.this, HomeScreenActivity.class));
152 | finish();
153 | }
154 |
155 | @Override
156 | public void onError(CometChatException e) {
157 | Toast.makeText(MainActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show();
158 | }
159 | });
160 | }
161 |
162 | public void createUser(View view) {
163 | startActivity(new Intent(this, CreateUserActivity.class));
164 | }
165 |
166 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/cometchat/pushnotificationsample/MessagesFragment.java:
--------------------------------------------------------------------------------
1 | package com.cometchat.pushnotificationsample;
2 |
3 | import android.os.Bundle;
4 | import android.text.TextUtils;
5 |
6 | import android.view.LayoutInflater;
7 | import android.view.View;
8 | import android.view.ViewGroup;
9 |
10 | import androidx.annotation.NonNull;
11 | import androidx.annotation.Nullable;
12 | import androidx.fragment.app.Fragment;
13 |
14 | import com.cometchat.chat.constants.CometChatConstants;
15 | import com.cometchat.chat.core.CometChat;
16 | import com.cometchat.chat.exceptions.CometChatException;
17 | import com.cometchat.chat.models.Group;
18 | import com.cometchat.chat.models.User;
19 | import com.cometchat.chatuikit.messages.CometChatMessages;
20 | import com.cometchat.chatuikit.shared.cometchatuikit.CometChatUIKit;
21 | import com.cometchat.chatuikit.shared.cometchatuikit.UIKitSettings;
22 | import com.cometchat.pushnotificationsample.helper.ConstantFile;
23 |
24 | import org.json.JSONException;
25 | import org.json.JSONObject;
26 |
27 | public class MessagesFragment extends Fragment {
28 | private CometChatMessages messages;
29 |
30 | @Override
31 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
32 | View view;
33 | if (!CometChat.isInitialized()) {
34 | UIKitSettings uiKitSettings = new UIKitSettings.UIKitSettingsBuilder().setRegion(AppConfig.AppDetails.REGION).setAppId(AppConfig.AppDetails.APP_ID).setAuthKey(AppConfig.AppDetails.AUTH_KEY).subscribePresenceForAllUsers().build();
35 | CometChatUIKit.init(getContext(), uiKitSettings, new CometChat.CallbackListener() {
36 | @Override
37 | public void onSuccess(String successString) {
38 | }
39 |
40 | @Override
41 | public void onError(CometChatException e) {
42 | }
43 | });
44 | }
45 | view = inflater.inflate(R.layout.fragment_messages, container, false);
46 | messages = view.findViewById(R.id.message_view);
47 | return view;
48 | }
49 |
50 | @Override
51 | public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
52 | super.onViewCreated(view, savedInstanceState);
53 | String payload = this.getArguments().getString(ConstantFile.IntentStrings.NOTIFICATION_PAYLOAD);
54 | if (!TextUtils.isEmpty(payload)) {
55 | User user = User.fromJson(payload);
56 | messages.setUser(user);
57 | try {
58 | JSONObject payloadObject = new JSONObject(payload);
59 | if (payloadObject.has(CometChatConstants.GroupKeys.KEY_GROUP_GUID)) {
60 | Group group = Group.fromJson(payloadObject.toString());
61 | messages.setGroup(group);
62 | } else {
63 | messages.setUser(User.fromJson(payloadObject.toString()));
64 | }
65 | } catch (JSONException e) {
66 | throw new RuntimeException(e);
67 | }
68 | }
69 | }
70 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/cometchat/pushnotificationsample/PushNotificationService.java:
--------------------------------------------------------------------------------
1 | package com.cometchat.pushnotificationsample;
2 |
3 | import androidx.annotation.NonNull;
4 |
5 | import com.cometchat.chat.core.CometChat;
6 | import com.cometchat.chat.exceptions.CometChatException;
7 | import com.google.firebase.messaging.FirebaseMessagingService;
8 | import com.google.firebase.messaging.RemoteMessage;
9 |
10 | public class PushNotificationService extends FirebaseMessagingService {
11 | CometChatNotification cometChatNotification;
12 |
13 | @Override
14 | public void onCreate() {
15 | super.onCreate();
16 | cometChatNotification = CometChatNotification.getInstance(this);
17 | }
18 |
19 | @Override
20 | public void onMessageReceived(@NonNull RemoteMessage remoteMessage) {
21 | super.onMessageReceived(remoteMessage);
22 | cometChatNotification.renderCometChatNotification(remoteMessage, new CometChat.CallbackListener() {
23 | @Override
24 | public void onSuccess(String s) {
25 | }
26 |
27 | @Override
28 | public void onError(CometChatException e) {
29 | }
30 | });
31 | }
32 |
33 | @Override
34 | public void onNewToken(@NonNull String token) {
35 | super.onNewToken(token);
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/app/src/main/java/com/cometchat/pushnotificationsample/SplashScreenActivity.java:
--------------------------------------------------------------------------------
1 | package com.cometchat.pushnotificationsample;
2 |
3 | import androidx.appcompat.app.AppCompatActivity;
4 | import androidx.localbroadcastmanager.content.LocalBroadcastManager;
5 |
6 | import android.content.BroadcastReceiver;
7 | import android.content.Context;
8 | import android.content.Intent;
9 | import android.content.IntentFilter;
10 | import android.os.Bundle;
11 |
12 | import com.cometchat.chat.core.CometChat;
13 | import com.cometchat.chat.exceptions.CometChatException;
14 | import com.cometchat.chatuikit.shared.cometchatuikit.CometChatUIKit;
15 | import com.cometchat.chatuikit.shared.cometchatuikit.UIKitSettings;
16 | import com.cometchat.pushnotificationsample.helper.ConstantFile;
17 |
18 | public class SplashScreenActivity extends AppCompatActivity {
19 |
20 | LocalBroadcastManager localBroadcastManager;
21 |
22 | @Override
23 | protected void onCreate(Bundle savedInstanceState) {
24 | super.onCreate(savedInstanceState);
25 | setContentView(R.layout.activity_splash);
26 | initCometChatUIKit();
27 | localBroadcastManager = LocalBroadcastManager.getInstance(this);
28 | localBroadcastManager.registerReceiver(callEventReceiver, new IntentFilter(ConstantFile.IntentStrings.COMETCHAT_CALL_EVENT));
29 |
30 | }
31 |
32 | private void initCometChatUIKit() {
33 | UIKitSettings uiKitSettings = new UIKitSettings.UIKitSettingsBuilder().setRegion(AppConfig.AppDetails.REGION).setAppId(AppConfig.AppDetails.APP_ID).setAuthKey(AppConfig.AppDetails.AUTH_KEY).subscribePresenceForAllUsers().build();
34 |
35 | CometChatUIKit.init(this, uiKitSettings, new CometChat.CallbackListener() {
36 | @Override
37 | public void onSuccess(String successString) {
38 | if (CometChatUIKit.getLoggedInUser() != null) {
39 | startActivity(new Intent(SplashScreenActivity.this, HomeScreenActivity.class));
40 | finish();
41 | } else {
42 | startActivity(new Intent(SplashScreenActivity.this, MainActivity.class));
43 | }
44 | }
45 |
46 | @Override
47 | public void onError(CometChatException e) {
48 | }
49 | });
50 | }
51 |
52 | private BroadcastReceiver callEventReceiver = new BroadcastReceiver() {
53 | @Override
54 | public void onReceive(Context context, Intent intent) {
55 | }
56 | };
57 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/cometchat/pushnotificationsample/helper/AppUtils.java:
--------------------------------------------------------------------------------
1 | package com.cometchat.pushnotificationsample.helper;
2 |
3 | import android.content.Context;
4 | import android.content.res.Configuration;
5 |
6 | import androidx.appcompat.app.AppCompatDelegate;
7 |
8 | import com.cometchat.chat.core.CometChat;
9 | import com.cometchat.chat.exceptions.CometChatException;
10 | import com.cometchat.chat.models.Group;
11 | import com.cometchat.chat.models.User;
12 | import com.cometchat.chatuikit.shared.resources.utils.Utils;
13 |
14 | import org.json.JSONArray;
15 | import org.json.JSONObject;
16 |
17 | import java.io.IOException;
18 | import java.io.InputStream;
19 | import java.util.ArrayList;
20 | import java.util.List;
21 |
22 | import okhttp3.Call;
23 | import okhttp3.Callback;
24 | import okhttp3.OkHttpClient;
25 | import okhttp3.Request;
26 | import okhttp3.Response;
27 |
28 | public class AppUtils {
29 | private static List userList = new ArrayList<>();
30 |
31 |
32 | public static void fetchSampleUsers(CometChat.CallbackListener> listener) {
33 | if (userList.isEmpty()) {
34 | Request request = new Request.Builder().url(ConstantFile.SampleUserString.SAMPLE_APP_USERS_URL).method("GET", null).build();
35 | OkHttpClient client = new OkHttpClient();
36 | client.newCall(request).enqueue(new Callback() {
37 | public void onFailure(Call call, IOException e) {
38 | Utils.runOnMainThread(() -> listener.onError(new CometChatException("11", e.getMessage())));
39 | }
40 |
41 | public void onResponse(Call call, Response response) {
42 | if (response.isSuccessful() && response.body() != null) {
43 | try {
44 | userList = processSampleUserList(response.body().string());
45 | } catch (IOException e) {
46 | Utils.runOnMainThread(() -> listener.onError(new CometChatException("10", e.getMessage())));
47 | }
48 | Utils.runOnMainThread(() -> listener.onSuccess(userList));
49 | } else {
50 | Utils.runOnMainThread(() -> listener.onError(new CometChatException("Unexpected code ", String.valueOf(response.code()))));
51 | }
52 | }
53 | });
54 | } else {
55 | Utils.runOnMainThread(() -> listener.onSuccess(userList));
56 | }
57 | }
58 |
59 | public static List processSampleUserList(String jsonString) {
60 | List users = new ArrayList<>();
61 | try {
62 | JSONObject jsonObject = new JSONObject(jsonString);
63 | JSONArray jsonArray = jsonObject.getJSONArray(ConstantFile.SampleUserString.KEY_USER);
64 | for (int i = 0; i < jsonArray.length(); i++) {
65 | JSONObject userJson = jsonArray.getJSONObject(i);
66 | User user = new User();
67 | user.setUid(userJson.getString(ConstantFile.SampleUserString.UID));
68 | user.setName(userJson.getString(ConstantFile.SampleUserString.NAME));
69 | user.setAvatar(userJson.getString(ConstantFile.SampleUserString.AVATAR));
70 | users.add(user);
71 | }
72 | } catch (Exception ignore) {
73 |
74 | }
75 | return users;
76 | }
77 |
78 | public static String loadJSONFromAsset(Context context) {
79 | String json = null;
80 | try {
81 | InputStream is = context.getAssets().open("SampleUsers.json");
82 | int size = is.available();
83 | byte[] buffer = new byte[size];
84 | is.read(buffer);
85 | is.close();
86 | json = new String(buffer, "UTF-8");
87 | } catch (IOException ex) {
88 | ex.printStackTrace();
89 | return null;
90 | }
91 | return json;
92 | }
93 |
94 | }
95 |
--------------------------------------------------------------------------------
/app/src/main/java/com/cometchat/pushnotificationsample/helper/CometChatObjectCallback.java:
--------------------------------------------------------------------------------
1 | package com.cometchat.pushnotificationsample.helper;
2 |
3 | import com.cometchat.chat.core.Call;
4 | import com.cometchat.chat.models.Group;
5 | import com.cometchat.chat.models.User;
6 |
7 | public interface CometChatObjectCallback {
8 | void onUserMessage(User user);
9 |
10 | void onGroupMessage(Group group);
11 |
12 | void onCallMessage();
13 |
14 | void onNoMessage();
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/app/src/main/java/com/cometchat/pushnotificationsample/helper/CometChatObjectHelper.java:
--------------------------------------------------------------------------------
1 | package com.cometchat.pushnotificationsample.helper;
2 |
3 | import android.content.Intent;
4 | import android.text.TextUtils;
5 |
6 | import com.cometchat.chat.constants.CometChatConstants;
7 | import com.cometchat.chat.core.CometChat;
8 | import com.cometchat.chat.exceptions.CometChatException;
9 | import com.cometchat.chat.models.Group;
10 | import com.cometchat.chat.models.User;
11 | import com.cometchat.pushnotificationsample.R;
12 |
13 | import org.json.JSONObject;
14 |
15 | public class CometChatObjectHelper {
16 | public static void process(Intent intent, final CometChatObjectCallback listener) {
17 | try {
18 | String notificationPayload = intent.getStringExtra(ConstantFile.IntentStrings.NOTIFICATION_PAYLOAD);
19 | if (TextUtils.isEmpty(notificationPayload)) {
20 | listener.onNoMessage();
21 | } else {
22 | JSONObject jsonObject = new JSONObject(notificationPayload);
23 | String type = jsonObject.getString(ConstantFile.IntentStrings.RECEIVER_TYPE);
24 | String msgtype = jsonObject.getString(ConstantFile.IntentStrings.TYPE);
25 | if (!msgtype.equals(CometChatConstants.CATEGORY_CALL)) {
26 | if (type.equals(CometChatConstants.RECEIVER_TYPE_USER)) {
27 | String uid = jsonObject.getString(ConstantFile.IntentStrings.SENDER);
28 |
29 | CometChat.getUser(uid, new CometChat.CallbackListener() {
30 | @Override
31 | public void onSuccess(User user) {
32 | listener.onUserMessage(user);
33 | }
34 |
35 | @Override
36 | public void onError(CometChatException e) {
37 | }
38 | });
39 |
40 | } else {
41 | String guid = jsonObject.getString(ConstantFile.IntentStrings.RECEIVER);
42 |
43 | CometChat.getGroup(guid, new CometChat.CallbackListener() {
44 | @Override
45 | public void onSuccess(Group group) {
46 | listener.onGroupMessage(group);
47 | }
48 |
49 | @Override
50 | public void onError(CometChatException e) {
51 | }
52 | });
53 | }
54 | }
55 | }
56 | } catch (Exception e) {
57 | e.printStackTrace();
58 | }
59 | }
60 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/cometchat/pushnotificationsample/helper/ConstantFile.java:
--------------------------------------------------------------------------------
1 | package com.cometchat.pushnotificationsample.helper;
2 |
3 | public class ConstantFile {
4 | public static final class IntentStrings {
5 | public static final String NAME = "name";
6 | public static final String TYPE = "type";
7 | public static final String ID = "id";
8 | public static final String RECEIVER = "receiver";
9 | public static final String SENDER = "sender";
10 | public static final String RECEIVER_ID = "id";
11 | public static final String SESSION_ID = "sessionId";
12 | public static final String RECEIVER_TYPE = "receiverType";
13 | public static final String CALL_TYPE = "callType";
14 | public static final String CALL_ACTION = "callAction";
15 | public static final String SENT_AT = "sentAt";
16 | public static final String RECEIVER_NAME = "receiverName";
17 | public static final String RECEIVER_AVATAR = "receiverAvatar";
18 | public static final String SENDER_AVATAR = "senderAvatar";
19 | public static final String CHAT = "chat";
20 | public static final String TAG = "tag";
21 | public static final String SENDER_NAME = "senderName";
22 | public static final String BODY = "body";
23 | public static final String NOTIFICATION_PAYLOAD = "notification_payload";
24 | public static final String MISSED = "Missed";
25 | public static final String REJECTED = "Rejected";
26 | public static final String COMETCHAT_CALL_EVENT = "CometChat_Call_Event";
27 | public static final String ORIGINAL_NUMBER = "OriginalNumber";
28 | public static final String MESSAGES = "Messages";
29 | }
30 |
31 | public static final class ErrorStrings {
32 | public static final String NOTIFICATION_NOT_REGISTERED = "Notifications Not Registered";
33 | public static final String FIREBASE_NOT_REGISTERED = "OriginalNumber";
34 |
35 | }
36 |
37 | public static final class SampleUserString {
38 | public static final String UID = "uid";
39 | public static final String NAME = "name";
40 | public static final String AVATAR = "avatar";
41 | public static final String KEY_USER = "users";
42 | public static final String SAMPLE_APP_USERS_URL = "https://assets.cometchat.io/sampleapp/sampledata.json";
43 |
44 | }
45 |
46 | }
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
15 |
18 |
21 |
22 |
23 |
24 |
30 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/captainamerica.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cometchat/cometchat-push-notification-app-android/927d97b12da615426de1de15fcba14cad63e1bcf/app/src/main/res/drawable/captainamerica.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/cometchat_white.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cometchat/cometchat-push-notification-app-android/927d97b12da615426de1de15fcba14cad63e1bcf/app/src/main/res/drawable/cometchat_white.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/curved_blue_button.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_arrow_right.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_arrow_right_selected.xml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
9 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_arrow_right_unselected.xml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
9 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_logout.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ironman.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cometchat/cometchat-push-notification-app-android/927d97b12da615426de1de15fcba14cad63e1bcf/app/src/main/res/drawable/ironman.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/spiderman.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cometchat/cometchat-push-notification-app-android/927d97b12da615426de1de15fcba14cad63e1bcf/app/src/main/res/drawable/spiderman.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/wolverine.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cometchat/cometchat-push-notification-app-android/927d97b12da615426de1de15fcba14cad63e1bcf/app/src/main/res/drawable/wolverine.png
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_call_screen.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
13 |
14 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_create_user.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
15 |
16 |
27 |
28 |
39 |
40 |
51 |
52 |
61 |
62 |
78 |
79 |
89 |
90 |
91 |
108 |
109 |
119 |
120 |
121 |
122 |
123 |
129 |
130 |
139 |
140 |
149 |
150 |
151 |
152 |
153 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_home_screen.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
13 |
14 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_login.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
12 |
13 |
25 |
26 |
37 |
38 |
50 |
51 |
58 |
59 |
75 |
76 |
87 |
88 |
89 |
97 |
98 |
99 |
100 |
113 |
114 |
122 |
123 |
127 |
128 |
137 |
138 |
139 |
140 |
141 |
142 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
16 |
17 |
18 |
22 |
23 |
28 |
29 |
36 |
37 |
48 |
49 |
50 |
51 |
56 |
57 |
66 |
67 |
70 |
71 |
78 |
79 |
82 |
83 |
96 |
97 |
104 |
105 |
109 |
110 |
116 |
117 |
123 |
124 |
125 |
137 |
138 |
139 |
140 |
154 |
155 |
162 |
163 |
167 |
168 |
174 |
175 |
181 |
182 |
183 |
195 |
196 |
197 |
198 |
199 |
200 |
203 |
204 |
218 |
219 |
226 |
227 |
231 |
232 |
238 |
239 |
245 |
246 |
247 |
259 |
260 |
261 |
262 |
276 |
277 |
284 |
285 |
289 |
290 |
296 |
297 |
303 |
304 |
305 |
317 |
318 |
319 |
320 |
321 |
322 |
328 |
329 |
334 |
335 |
342 |
343 |
344 |
345 |
346 |
354 |
355 |
370 |
371 |
372 |
373 |
377 |
378 |
386 |
387 |
391 |
392 |
400 |
401 |
402 |
403 |
404 |
405 |
406 |
407 |
408 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_splash.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_conversation.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_messages.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/view_menu.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
14 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v33/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cometchat/cometchat-push-notification-app-android/927d97b12da615426de1de15fcba14cad63e1bcf/app/src/main/res/mipmap-hdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cometchat/cometchat-push-notification-app-android/927d97b12da615426de1de15fcba14cad63e1bcf/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cometchat/cometchat-push-notification-app-android/927d97b12da615426de1de15fcba14cad63e1bcf/app/src/main/res/mipmap-mdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cometchat/cometchat-push-notification-app-android/927d97b12da615426de1de15fcba14cad63e1bcf/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cometchat/cometchat-push-notification-app-android/927d97b12da615426de1de15fcba14cad63e1bcf/app/src/main/res/mipmap-xhdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cometchat/cometchat-push-notification-app-android/927d97b12da615426de1de15fcba14cad63e1bcf/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cometchat/cometchat-push-notification-app-android/927d97b12da615426de1de15fcba14cad63e1bcf/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cometchat/cometchat-push-notification-app-android/927d97b12da615426de1de15fcba14cad63e1bcf/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cometchat/cometchat-push-notification-app-android/927d97b12da615426de1de15fcba14cad63e1bcf/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cometchat/cometchat-push-notification-app-android/927d97b12da615426de1de15fcba14cad63e1bcf/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/values-night/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
16 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #6929ca
4 | #581fac
5 | #581fac
6 | #FF03DAC5
7 | #FF018786
8 | #FF000000
9 | #FFFFFFFF
10 | #efeef3
11 |
12 | #6929ca
13 | #581fac
14 | #2196F3
15 | #000000
16 |
17 | #FFFFFF
18 | #FAFAFA
19 | #6b000000
20 | #EEEEEE
21 | #e0e0e0
22 | #40bdbdbd
23 | #E64CAF50
24 | #eecc0000
25 | #ECECEC
26 |
27 | #FF9800
28 | #8867C5
29 | #0020F5
30 | #43A047
31 | #E53935
32 | #B96B6B6B
33 | #C4C4C4
34 | #9E9C9C
35 | #202124
36 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | CometChatPushNotificationSample
3 | Unable to end call due to ${p0?.code}
4 | Error
5 | Call
6 | You tried to call
7 | Fetching FCM registration token failed
8 | Fill Username field
9 | VoIP Permission
10 | Open Settings
11 | Cancel
12 | com.android.server.telecom
13 | "com.android.server.telecom.settings.EnableAccountPreferenceActivity"
14 | To make VoIP Calling work properly, you need to allow certain permission from your call account settings for this app.
15 | Please wait...
16 | No sample users available
17 | Fill this field
18 |
19 |
--------------------------------------------------------------------------------
/app/src/main/res/values/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
16 |
--------------------------------------------------------------------------------
/app/src/main/res/xml/backup_rules.xml:
--------------------------------------------------------------------------------
1 |
8 |
9 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/xml/data_extraction_rules.xml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
8 |
12 |
13 |
19 |
--------------------------------------------------------------------------------
/app/src/test/java/com/cometchat/pushnotificationsample/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.cometchat.pushnotificationsample;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 | plugins {
3 | id 'com.android.application' version '8.3.2' apply false
4 | id 'com.android.library' version '8.3.2' apply false
5 | id 'com.google.gms.google-services' version '4.3.15' apply false
6 | }
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 | # AndroidX package structure to make it clearer which packages are bundled with the
15 | # Android operating system, and which are packaged with your app's APK
16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
17 | android.useAndroidX=true
18 | # Enables namespacing of each library's R class so that its R class includes only the
19 | # resources declared in the library itself and none from the library's dependencies,
20 | # thereby reducing the size of the R class for that library
21 | android.nonTransitiveRClass=true
22 |
23 | android.enableJetifier=true
24 | android.defaults.buildfeatures.buildconfig=true
25 | android.nonFinalResIds=false
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cometchat/cometchat-push-notification-app-android/927d97b12da615426de1de15fcba14cad63e1bcf/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Tue Sep 05 01:20:26 IST 2023
2 | distributionBase=GRADLE_USER_HOME
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
4 | distributionPath=wrapper/dists
5 | zipStorePath=wrapper/dists
6 | zipStoreBase=GRADLE_USER_HOME
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | #
4 | # Copyright 2015 the original author or authors.
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # https://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | ##############################################################################
20 | ##
21 | ## Gradle start up script for UN*X
22 | ##
23 | ##############################################################################
24 |
25 | # Attempt to set APP_HOME
26 | # Resolve links: $0 may be a link
27 | PRG="$0"
28 | # Need this for relative symlinks.
29 | while [ -h "$PRG" ] ; do
30 | ls=`ls -ld "$PRG"`
31 | link=`expr "$ls" : '.*-> \(.*\)$'`
32 | if expr "$link" : '/.*' > /dev/null; then
33 | PRG="$link"
34 | else
35 | PRG=`dirname "$PRG"`"/$link"
36 | fi
37 | done
38 | SAVED="`pwd`"
39 | cd "`dirname \"$PRG\"`/" >/dev/null
40 | APP_HOME="`pwd -P`"
41 | cd "$SAVED" >/dev/null
42 |
43 | APP_NAME="Gradle"
44 | APP_BASE_NAME=`basename "$0"`
45 |
46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
48 |
49 | # Use the maximum available, or set MAX_FD != -1 to use that value.
50 | MAX_FD="maximum"
51 |
52 | warn () {
53 | echo "$*"
54 | }
55 |
56 | die () {
57 | echo
58 | echo "$*"
59 | echo
60 | exit 1
61 | }
62 |
63 | # OS specific support (must be 'true' or 'false').
64 | cygwin=false
65 | msys=false
66 | darwin=false
67 | nonstop=false
68 | case "`uname`" in
69 | CYGWIN* )
70 | cygwin=true
71 | ;;
72 | Darwin* )
73 | darwin=true
74 | ;;
75 | MINGW* )
76 | msys=true
77 | ;;
78 | NONSTOP* )
79 | nonstop=true
80 | ;;
81 | esac
82 |
83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
84 |
85 |
86 | # Determine the Java command to use to start the JVM.
87 | if [ -n "$JAVA_HOME" ] ; then
88 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
89 | # IBM's JDK on AIX uses strange locations for the executables
90 | JAVACMD="$JAVA_HOME/jre/sh/java"
91 | else
92 | JAVACMD="$JAVA_HOME/bin/java"
93 | fi
94 | if [ ! -x "$JAVACMD" ] ; then
95 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
96 |
97 | Please set the JAVA_HOME variable in your environment to match the
98 | location of your Java installation."
99 | fi
100 | else
101 | JAVACMD="java"
102 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
103 |
104 | Please set the JAVA_HOME variable in your environment to match the
105 | location of your Java installation."
106 | fi
107 |
108 | # Increase the maximum file descriptors if we can.
109 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
110 | MAX_FD_LIMIT=`ulimit -H -n`
111 | if [ $? -eq 0 ] ; then
112 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
113 | MAX_FD="$MAX_FD_LIMIT"
114 | fi
115 | ulimit -n $MAX_FD
116 | if [ $? -ne 0 ] ; then
117 | warn "Could not set maximum file descriptor limit: $MAX_FD"
118 | fi
119 | else
120 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
121 | fi
122 | fi
123 |
124 | # For Darwin, add options to specify how the application appears in the dock
125 | if $darwin; then
126 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
127 | fi
128 |
129 | # For Cygwin or MSYS, switch paths to Windows format before running java
130 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
131 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
132 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
133 |
134 | JAVACMD=`cygpath --unix "$JAVACMD"`
135 |
136 | # We build the pattern for arguments to be converted via cygpath
137 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
138 | SEP=""
139 | for dir in $ROOTDIRSRAW ; do
140 | ROOTDIRS="$ROOTDIRS$SEP$dir"
141 | SEP="|"
142 | done
143 | OURCYGPATTERN="(^($ROOTDIRS))"
144 | # Add a user-defined pattern to the cygpath arguments
145 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
146 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
147 | fi
148 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
149 | i=0
150 | for arg in "$@" ; do
151 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
152 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
153 |
154 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
155 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
156 | else
157 | eval `echo args$i`="\"$arg\""
158 | fi
159 | i=`expr $i + 1`
160 | done
161 | case $i in
162 | 0) set -- ;;
163 | 1) set -- "$args0" ;;
164 | 2) set -- "$args0" "$args1" ;;
165 | 3) set -- "$args0" "$args1" "$args2" ;;
166 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;;
167 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
168 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
169 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
170 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
171 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
172 | esac
173 | fi
174 |
175 | # Escape application args
176 | save () {
177 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
178 | echo " "
179 | }
180 | APP_ARGS=`save "$@"`
181 |
182 | # Collect all arguments for the java command, following the shell quoting and substitution rules
183 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
184 |
185 | exec "$JAVACMD" "$@"
186 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @rem
2 | @rem Copyright 2015 the original author or authors.
3 | @rem
4 | @rem Licensed under the Apache License, Version 2.0 (the "License");
5 | @rem you may not use this file except in compliance with the License.
6 | @rem You may obtain a copy of the License at
7 | @rem
8 | @rem https://www.apache.org/licenses/LICENSE-2.0
9 | @rem
10 | @rem Unless required by applicable law or agreed to in writing, software
11 | @rem distributed under the License is distributed on an "AS IS" BASIS,
12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | @rem See the License for the specific language governing permissions and
14 | @rem limitations under the License.
15 | @rem
16 |
17 | @if "%DEBUG%" == "" @echo off
18 | @rem ##########################################################################
19 | @rem
20 | @rem Gradle startup script for Windows
21 | @rem
22 | @rem ##########################################################################
23 |
24 | @rem Set local scope for the variables with windows NT shell
25 | if "%OS%"=="Windows_NT" setlocal
26 |
27 | set DIRNAME=%~dp0
28 | if "%DIRNAME%" == "" set DIRNAME=.
29 | set APP_BASE_NAME=%~n0
30 | set APP_HOME=%DIRNAME%
31 |
32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter.
33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
34 |
35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
37 |
38 | @rem Find java.exe
39 | if defined JAVA_HOME goto findJavaFromJavaHome
40 |
41 | set JAVA_EXE=java.exe
42 | %JAVA_EXE% -version >NUL 2>&1
43 | if "%ERRORLEVEL%" == "0" goto execute
44 |
45 | echo.
46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
47 | echo.
48 | echo Please set the JAVA_HOME variable in your environment to match the
49 | echo location of your Java installation.
50 |
51 | goto fail
52 |
53 | :findJavaFromJavaHome
54 | set JAVA_HOME=%JAVA_HOME:"=%
55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
56 |
57 | if exist "%JAVA_EXE%" goto execute
58 |
59 | echo.
60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
61 | echo.
62 | echo Please set the JAVA_HOME variable in your environment to match the
63 | echo location of your Java installation.
64 |
65 | goto fail
66 |
67 | :execute
68 | @rem Setup the command line
69 |
70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
71 |
72 |
73 | @rem Execute Gradle
74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
75 |
76 | :end
77 | @rem End local scope for the variables with windows NT shell
78 | if "%ERRORLEVEL%"=="0" goto mainEnd
79 |
80 | :fail
81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
82 | rem the _cmd.exe /c_ return code!
83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
84 | exit /b 1
85 |
86 | :mainEnd
87 | if "%OS%"=="Windows_NT" endlocal
88 |
89 | :omega
90 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | pluginManagement {
2 | repositories {
3 | google()
4 | mavenCentral()
5 | gradlePluginPortal()
6 | }
7 | }
8 | dependencyResolutionManagement {
9 | repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
10 | repositories {
11 | google()
12 | mavenCentral()
13 | maven{
14 | url "https://dl.cloudsmith.io/public/cometchat/cometchat/maven/"
15 | }
16 | }
17 | }
18 | rootProject.name = "CometChatPushNotificationSample"
19 | include ':app'
20 |
--------------------------------------------------------------------------------