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",
|
"type": "SINGLE",
|
||||||
"filters": [],
|
"filters": [],
|
||||||
"attributes": [],
|
"attributes": [],
|
||||||
"versionCode": 8000035,
|
"versionCode": 8000091,
|
||||||
"versionName": "8.0.35",
|
"versionName": "8.0.91",
|
||||||
"outputFile": "SafeDispatchMobile_v.8.0.35-release.apk"
|
"outputFile": "SafeDispatchMobile_v.8.0.91-release.apk"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"elementType": "File"
|
"elementType": "File"
|
||||||
|
@ -60,6 +60,7 @@ import android.annotation.SuppressLint;
|
|||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
import android.app.Notification;
|
import android.app.Notification;
|
||||||
|
import android.app.NotificationChannel;
|
||||||
import android.app.NotificationManager;
|
import android.app.NotificationManager;
|
||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
@ -74,6 +75,7 @@ import android.content.res.Configuration;
|
|||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
@ -94,6 +96,8 @@ import android.widget.Toast;
|
|||||||
import android.widget.TabHost.TabSpec;
|
import android.widget.TabHost.TabSpec;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.core.app.NotificationCompat;
|
||||||
|
import androidx.core.app.NotificationManagerCompat;
|
||||||
|
|
||||||
public class TabLayoutActivity extends AbstractSDParentActivity {
|
public class TabLayoutActivity extends AbstractSDParentActivity {
|
||||||
|
|
||||||
@ -1857,16 +1861,6 @@ public class TabLayoutActivity extends AbstractSDParentActivity {
|
|||||||
SM.Debug("Unit imei:" + tempArr[0]);
|
SM.Debug("Unit imei:" + tempArr[0]);
|
||||||
String unitIMEI = tempArr[0];
|
String unitIMEI = tempArr[0];
|
||||||
|
|
||||||
//==============
|
|
||||||
// alarms tab
|
|
||||||
//==============
|
|
||||||
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
|
// change Visual Elements
|
||||||
setImei(unitIMEI);
|
setImei(unitIMEI);
|
||||||
switch (msg.opCode) {
|
switch (msg.opCode) {
|
||||||
@ -1925,6 +1919,11 @@ public class TabLayoutActivity extends AbstractSDParentActivity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//list for SMS
|
||||||
|
if (AppParams.crtTab == AppParams.Tabs.alarms) {
|
||||||
|
SM.Debug("currentActivity instanceof AlarmActivity - newSMS | " + tempArr[0] + " | " + tempArr[1]);
|
||||||
|
getAlarms(AppParams.USERID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2211,23 +2210,47 @@ public class TabLayoutActivity extends AbstractSDParentActivity {
|
|||||||
|
|
||||||
Notification notification = new Notification(icon, tickerText, System.currentTimeMillis());
|
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
|
// flag that the notification will be closed when clicked
|
||||||
notification.flags |= Notification.FLAG_AUTO_CANCEL;
|
notification.flags |= Notification.FLAG_AUTO_CANCEL;
|
||||||
notification.number = 1; // the same notification will be shown;
|
notification.number = 1; // the same notification will be shown;
|
||||||
notification.tickerText = tickerText; // notification text when arrives
|
notification.tickerText = tickerText; // notification text when arrives
|
||||||
notification.sound = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.new_sms);
|
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
|
// return vehicle according to imei
|
||||||
|
Loading…
Reference in New Issue
Block a user