Commit 58b67311 by Kunj Gupta

Fixed - Remove Create Incident notification when on chat screen.

parent b66050a9
package com.vsoft.servicenow.service;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Build;
import android.support.v4.app.NotificationCompat;
import android.support.v4.content.LocalBroadcastManager;
......@@ -37,6 +39,8 @@ public class NotificationMessagingService extends FirebaseMessagingService {
private static final String FCM_KEY_SHORT_DESCRIPTION = "short_description";
private static final String FCM_KEY_CREATED_BY = "created_by";
private static final String CHANNEL_ID = "sn_channel";
/**
* This is default constructor of NotificationMessagingService.
*/
......@@ -94,10 +98,19 @@ public class NotificationMessagingService extends FirebaseMessagingService {
.setContentText(notification.getShortDescription())
.setAutoCancel(true)
.setContentIntent(pendingIntent)
.setChannelId(CHANNEL_ID)
.setSound(defaultSoundUri);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
CharSequence name = getString(R.string.app_name);// The user-visible name of the channel.
int importance = NotificationManager.IMPORTANCE_DEFAULT;
NotificationChannel mChannel = new NotificationChannel(CHANNEL_ID, name, importance);
notificationManager.createNotificationChannel(mChannel);
}
notificationManager.notify(1, notificationBuilder.build());
}
......
package com.vsoft.servicenow.ui;
import android.app.NotificationManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Color;
import android.os.Bundle;
import android.speech.tts.TextToSpeech;
import android.speech.tts.UtteranceProgressListener;
import android.support.v4.content.LocalBroadcastManager;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.util.Log;
import android.view.KeyEvent;
import android.view.MenuItem;
import android.view.MotionEvent;
......@@ -50,7 +59,7 @@ import java.util.List;
/**
* A chat Activity containing messages view and input form.
*/
public class ChatActivity extends HandleNotificationActivity implements OnDSListener, OnDSPermissionsListener {
public class ChatActivity extends AppCompatActivity implements OnDSListener, OnDSPermissionsListener {
private static final String TAG = "ChatActivity";
......@@ -99,6 +108,27 @@ public class ChatActivity extends HandleNotificationActivity implements OnDSList
}
@Override
public void onResume() {
super.onResume();
LocalBroadcastManager.getInstance(this)
.registerReceiver(mMessageReceiver,
new IntentFilter(Constants.BROADCAST_NOTIFICATION));
}
private final BroadcastReceiver mMessageReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
CatalogueLog.e("Notification Receive");
final NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
//Play notification sound because Above we already cancel notifications.
// That's why we need to play explicitly
Util.playNotificationSound(ChatActivity.this);
}
};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
......@@ -516,7 +546,8 @@ public class ChatActivity extends HandleNotificationActivity implements OnDSList
@Override
public void onPause() {
super.onPause();
LocalBroadcastManager.getInstance(this)
.unregisterReceiver(mMessageReceiver);
if(speaker!=null && speaker.isSpeaking()) {
speaker.stop();
}
......@@ -524,6 +555,7 @@ public class ChatActivity extends HandleNotificationActivity implements OnDSList
droidSpeech.closeDroidSpeechOperations();
}
CURRENT_STATE = NONE;
super.onPause();
}
@Override
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment