Commit eb61db35 by 宁斌

1、長連接通知欄調整

parent 7e27ec13
......@@ -166,6 +166,7 @@ public class PrintActivity extends BaseActivity<PrintPresenter> implements Print
@Override
public void connectionError(Exception e) {
printerResult = false;
printerLoadingDialog.setStep(2, PrinterLoadingDialog.status_error, e.getMessage());
}
......@@ -192,6 +193,7 @@ public class PrintActivity extends BaseActivity<PrintPresenter> implements Print
@Override
public void onPrintError(Exception e, int errorCode) {
printerResult = false;
printerLoadingDialog.setStep(3, PrinterLoadingDialog.status_error, e.getMessage());
}
});
......@@ -515,8 +517,8 @@ public class PrintActivity extends BaseActivity<PrintPresenter> implements Print
@Override
public void printSuccess() {
LoganManager.w_printer(TAG, "printFailure 打印成功");
CC.sendCCResult(callId, CCResult.success());
killMyself();
CC.sendCCResult(callId, CCResult.success());
}
@Override
......
......@@ -132,9 +132,9 @@ class DataNotificationService : Service() {
if (mCurrConnectionType == OPEN_DELIVET_ORDER_CONNECTION) {
// 在API11之后构建Notification的方式
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
createNotificationChannel()
createNotificationChannel("Ricepon Pos", "外賣接單服務")
} else {
startNotification()
startNotification("Ricepon Pos", "外賣接單服務")
}
}
if (isCreate) {
......@@ -150,7 +150,7 @@ class DataNotificationService : Service() {
* 创建通知渠道
*/
@RequiresApi(Build.VERSION_CODES.O)
fun createNotificationChannel() {
fun createNotificationChannel(title: String, text: String) {
if (!UserContext.newInstance().isLogin) {
stopSelf()
return
......@@ -166,11 +166,11 @@ class DataNotificationService : Service() {
val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
notificationManager.createNotificationChannel(channel)
notificationManager.cancelAll()
startNotification()
startNotification(title, text)
}
@SuppressLint("InflateParams")
private fun startNotification() {
private fun startNotification(title: String, text: String) {
val broadcastReceiver = Intent(AppConstans.CLEAR_ORDER_RECEIVING_HEART)
val broadcastIntent = PendingIntent.getBroadcast(this, 10, broadcastReceiver, 0)
val remoteViews = RemoteViews(packageName, R.layout.layout_order_receiving)
......@@ -187,8 +187,8 @@ class DataNotificationService : Service() {
//在创建的通知渠道上发送通知
val builder = NotificationCompat.Builder(this, CHANNEL_ID)
builder.setSmallIcon(R.mipmap.ic_launcher) //设置通知图标
.setContentTitle("Ricepon Pos")//设置通知标题
.setContentText("外賣接單服務")//设置通知内容Takeaway order service
.setContentTitle(title)//设置通知标题
.setContentText(text)//设置通知内容Takeaway order service
.setContent(remoteViews)
.setContentIntent(pendingIntent)
.setAutoCancel(false) //用户触摸时,自动关闭
......@@ -198,12 +198,15 @@ class DataNotificationService : Service() {
startForeground(123, builder.build())
}
fun cleanNotification() {
// val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
// notificationManager.cancelAll()
// notificationManager.cancel(123)
// //停止前台服務
// stopForeground(true)
fun restartNotification() {
//先停止前台服務
stopForeground(true)
// 在API11之后构建Notification的方式
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
createNotificationChannel("Ricepon Pos", "打印服務")
} else {
startNotification("Ricepon Pos", "打印服務")
}
}
inner class MyBind : Binder() {
......@@ -212,9 +215,9 @@ class DataNotificationService : Service() {
set(value) {
field = value
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
createNotificationChannel()
createNotificationChannel("Ricepon Pos", "外賣接單服務")
} else {
startNotification()
startNotification("Ricepon Pos", "外賣接單服務")
}
}
......@@ -427,7 +430,7 @@ class DataNotificationService : Service() {
private fun clearHeart() {
val requestBody = FormBody.Builder()
.add("restaurantId", RestaurantInfoManager.newInstance().restaurantId .toString())
.add("restaurantId", RestaurantInfoManager.newInstance().restaurantId.toString())
.build()
OkHttp3Utils.post(HttpsConstans.ROOT_URL + "/member-web/api/restaurant/clearHeartbeat", requestBody)
.subscribeOn(Schedulers.io()).subscribe()
......@@ -437,7 +440,7 @@ class DataNotificationService : Service() {
override fun onReceive(context: Context?, intent: Intent?) {
//關閉service,會調用service的onDestroy
// stopSelf()
cleanNotification()
restartNotification()
mCurrConnectionType = OPEN_OTHER_CONNECTION;
send(mCurrConnectionType)
}
......
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 to comment