Merge pull request 'fix notifications' (#29) from show_notifications into develop
Reviewed-on: #29
This commit is contained in:
commit
8a9ea703c7
Binary file not shown.
Binary file not shown.
@ -11,9 +11,9 @@
|
||||
"type": "SINGLE",
|
||||
"filters": [],
|
||||
"attributes": [],
|
||||
"versionCode": 8000035,
|
||||
"versionName": "8.0.35",
|
||||
"outputFile": "SafeDispatchMobile_v.8.0.35-release.apk"
|
||||
"versionCode": 8000091,
|
||||
"versionName": "8.0.91",
|
||||
"outputFile": "SafeDispatchMobile_v.8.0.91-release.apk"
|
||||
}
|
||||
],
|
||||
"elementType": "File"
|
||||
|
@ -60,6 +60,7 @@ import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.app.Dialog;
|
||||
import android.app.Notification;
|
||||
import android.app.NotificationChannel;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.BroadcastReceiver;
|
||||
@ -74,6 +75,7 @@ import android.content.res.Configuration;
|
||||
import android.content.res.Resources;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.IBinder;
|
||||
@ -94,6 +96,8 @@ import android.widget.Toast;
|
||||
import android.widget.TabHost.TabSpec;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.core.app.NotificationCompat;
|
||||
import androidx.core.app.NotificationManagerCompat;
|
||||
|
||||
public class TabLayoutActivity extends AbstractSDParentActivity {
|
||||
|
||||
@ -1857,75 +1861,70 @@ public class TabLayoutActivity extends AbstractSDParentActivity {
|
||||
SM.Debug("Unit imei:" + tempArr[0]);
|
||||
String unitIMEI = tempArr[0];
|
||||
|
||||
//==============
|
||||
// alarms tab
|
||||
//==============
|
||||
// change Visual Elements
|
||||
setImei(unitIMEI);
|
||||
switch (msg.opCode) {
|
||||
case 135:
|
||||
setMess("speed " + tempArr[1]);
|
||||
break;
|
||||
case 136:
|
||||
setMess("landmark " + tempArr[1]);
|
||||
break;
|
||||
case 137:
|
||||
setMess("zone " + tempArr[1]);
|
||||
break;
|
||||
case 138:
|
||||
setMess("emergency");
|
||||
break;
|
||||
case 140:
|
||||
setMess("telemetry " + tempArr[1]);
|
||||
break;
|
||||
default:
|
||||
setMess("emergency");
|
||||
}
|
||||
myHandler.post(updateResultsAlarm);
|
||||
|
||||
//============
|
||||
// live tab
|
||||
//============
|
||||
|
||||
if ((msg.opCode == 138) && (AppParams.crtTab == AppParams.Tabs.live)) {
|
||||
SuperVehicle superVehicle = getSuperVehHash().get(Long.parseLong(unitIMEI));
|
||||
|
||||
if (superVehicle != null) {
|
||||
|
||||
//if is not check i need to force check to put on the map
|
||||
boolean forceChecked = false;
|
||||
if (!superVehicle.needUpdate) {
|
||||
superVehicle.needUpdate = true;
|
||||
forceChecked = true;
|
||||
}
|
||||
|
||||
try {
|
||||
int x = 0;
|
||||
if (forceChecked) {
|
||||
for (Vehicle veh : getAllVehicle()) {
|
||||
if (veh.imei.compareTo(unitIMEI) == 0) break;
|
||||
x++;
|
||||
}
|
||||
} else x = -1;
|
||||
if (getLiveActivity() != null) {
|
||||
if (x != getAllVehicle().size())
|
||||
getLiveActivity().emergencyAlarmReceived(x, superVehicle.lat, superVehicle.lng);
|
||||
else
|
||||
getLiveActivity().emergencyAlarmReceived(-1, superVehicle.lat, superVehicle.lng);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
SM.Debug(HASH_ERROR_MESSAGE + ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//list for SMS
|
||||
if (AppParams.crtTab == AppParams.Tabs.alarms) {
|
||||
SM.Debug("currentActivity instanceof AlarmActivity - newSMS | " + tempArr[0] + " | " + tempArr[1]);
|
||||
getAlarms(AppParams.USERID);
|
||||
}
|
||||
|
||||
// if tab is not TextTab
|
||||
if (tabHost.getCurrentTab() != 5 /* Text tab */) {
|
||||
// change Visual Elements
|
||||
setImei(unitIMEI);
|
||||
switch (msg.opCode) {
|
||||
case 135:
|
||||
setMess("speed " + tempArr[1]);
|
||||
break;
|
||||
case 136:
|
||||
setMess("landmark " + tempArr[1]);
|
||||
break;
|
||||
case 137:
|
||||
setMess("zone " + tempArr[1]);
|
||||
break;
|
||||
case 138:
|
||||
setMess("emergency");
|
||||
break;
|
||||
case 140:
|
||||
setMess("telemetry " + tempArr[1]);
|
||||
break;
|
||||
default:
|
||||
setMess("emergency");
|
||||
}
|
||||
myHandler.post(updateResultsAlarm);
|
||||
|
||||
//============
|
||||
// live tab
|
||||
//============
|
||||
|
||||
if ((msg.opCode == 138) && (AppParams.crtTab == AppParams.Tabs.live)) {
|
||||
SuperVehicle superVehicle = getSuperVehHash().get(Long.parseLong(unitIMEI));
|
||||
|
||||
if (superVehicle != null) {
|
||||
|
||||
//if is not check i need to force check to put on the map
|
||||
boolean forceChecked = false;
|
||||
if (!superVehicle.needUpdate) {
|
||||
superVehicle.needUpdate = true;
|
||||
forceChecked = true;
|
||||
}
|
||||
|
||||
try {
|
||||
int x = 0;
|
||||
if (forceChecked) {
|
||||
for (Vehicle veh : getAllVehicle()) {
|
||||
if (veh.imei.compareTo(unitIMEI) == 0) break;
|
||||
x++;
|
||||
}
|
||||
} else x = -1;
|
||||
if (getLiveActivity() != null) {
|
||||
if (x != getAllVehicle().size())
|
||||
getLiveActivity().emergencyAlarmReceived(x, superVehicle.lat, superVehicle.lng);
|
||||
else
|
||||
getLiveActivity().emergencyAlarmReceived(-1, superVehicle.lat, superVehicle.lng);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
SM.Debug(HASH_ERROR_MESSAGE + ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -2211,23 +2210,47 @@ public class TabLayoutActivity extends AbstractSDParentActivity {
|
||||
|
||||
Notification notification = new Notification(icon, tickerText, System.currentTimeMillis());
|
||||
|
||||
// set intent to be opened on NotificationClick
|
||||
/* Notification */
|
||||
Intent notificationIntent = new Intent(this, NotificationActivity.class);
|
||||
notificationIntent.putExtra("key", iconValue);
|
||||
|
||||
// cancel old notification
|
||||
mNotificationManager.cancel(icon);
|
||||
|
||||
PendingIntent contentIntent = PendingIntent.getActivity(context, NOTIFICATION_ACTIVITY_RESULT, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT);
|
||||
|
||||
// flag that the notification will be closed when clicked
|
||||
notification.flags |= Notification.FLAG_AUTO_CANCEL;
|
||||
notification.number = 1; // the same notification will be shown;
|
||||
notification.tickerText = tickerText; // notification text when arrives
|
||||
notification.sound = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.new_sms);
|
||||
// add notification to the manager
|
||||
mNotificationManager.notify(icon, notification);
|
||||
|
||||
|
||||
Intent intent = new Intent(this, NotificationActivity.class);
|
||||
intent.putExtra("key", iconValue);
|
||||
|
||||
// cancel old notification
|
||||
mNotificationManager.cancel(icon);
|
||||
|
||||
PendingIntent pendingIntent = PendingIntent.getActivity(context, NOTIFICATION_ACTIVITY_RESULT, intent, PendingIntent.FLAG_CANCEL_CURRENT);
|
||||
createNotificationChannel(icon, contentTitle, contentText, pendingIntent);
|
||||
}
|
||||
|
||||
private void createNotificationChannel(int icon, String title, String text, PendingIntent pendingIntent) {
|
||||
// Create the NotificationChannel, but only on API 26+ because
|
||||
// the NotificationChannel class is new and not in the support library
|
||||
String notificationChannelID = String.valueOf(icon);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
CharSequence name = "Notification Channel";
|
||||
int importance = NotificationManager.IMPORTANCE_HIGH;
|
||||
NotificationChannel channel = new NotificationChannel(notificationChannelID, name, importance);
|
||||
// Register the channel with the system; you can't change the importance
|
||||
// or other notification behaviors after this
|
||||
NotificationManager notificationManager = getSystemService(NotificationManager.class);
|
||||
notificationManager.createNotificationChannel(channel);
|
||||
}
|
||||
|
||||
NotificationCompat.Builder builder = new NotificationCompat.Builder(context, notificationChannelID)
|
||||
.setSmallIcon(icon)
|
||||
.setContentTitle(title)
|
||||
.setContentText(text)
|
||||
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
|
||||
.setAutoCancel(true)
|
||||
.setContentIntent(pendingIntent);
|
||||
|
||||
NotificationManagerCompat managerCompat = NotificationManagerCompat.from(context);
|
||||
managerCompat.notify(icon, builder.build());
|
||||
}
|
||||
|
||||
// return vehicle according to imei
|
||||
|
Loading…
Reference in New Issue
Block a user