added notification channels for oreo (not tested due to lack of device)
This commit is contained in:
@ -1,9 +1,7 @@
|
||||
package com.tutpro.baresip
|
||||
|
||||
import android.app.*
|
||||
import android.app.Notification.VISIBILITY_PUBLIC
|
||||
import android.app.NotificationManager
|
||||
import android.app.PendingIntent
|
||||
import android.app.Service
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
@ -21,6 +19,7 @@ import java.io.File
|
||||
import java.io.FileInputStream
|
||||
import java.io.ObjectInputStream
|
||||
import android.support.v4.content.LocalBroadcastManager
|
||||
import android.os.Build
|
||||
|
||||
class BaresipService: Service() {
|
||||
|
||||
@ -43,8 +42,9 @@ class BaresipService: Service() {
|
||||
intent.setPackage("com.tutpro.baresip")
|
||||
|
||||
nm = getSystemService(NOTIFICATION_SERVICE) as NotificationManager
|
||||
snb = NotificationCompat.Builder(this)
|
||||
cnb = NotificationCompat.Builder(this)
|
||||
createNotificationChannels()
|
||||
snb = NotificationCompat.Builder(this, DEFAULT_CHANNEL_ID)
|
||||
cnb = NotificationCompat.Builder(this, HIGH_CHANNEL_ID)
|
||||
|
||||
ni = Intent(this, MainActivity::class.java)
|
||||
.setAction(Intent.ACTION_MAIN)
|
||||
@ -127,12 +127,12 @@ class BaresipService: Service() {
|
||||
Thread(Runnable { baresipStart(path) }).start()
|
||||
BaresipService.IS_SERVICE_RUNNING = true
|
||||
registerReceiver(nr, IntentFilter("android.net.conn.CONNECTIVITY_CHANGE"))
|
||||
showNotification()
|
||||
showStatusNotification()
|
||||
if (!RUN_FOREGROUNG) super.onStartCommand(intent, flags, startId)
|
||||
}
|
||||
|
||||
"UpdateNotification" -> {
|
||||
updateNotification()
|
||||
updateStatusNotification()
|
||||
}
|
||||
|
||||
"Stop" -> {
|
||||
@ -164,11 +164,26 @@ class BaresipService: Service() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun showNotification() {
|
||||
private fun createNotificationChannels() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
val defaultChannel = NotificationChannel(DEFAULT_CHANNEL_ID, "Default",
|
||||
NotificationManager.IMPORTANCE_DEFAULT)
|
||||
defaultChannel.description = "Tells that baresip is running"
|
||||
defaultChannel.lockscreenVisibility = Notification.VISIBILITY_PUBLIC
|
||||
nm.createNotificationChannel(defaultChannel)
|
||||
val highChannel = NotificationChannel(HIGH_CHANNEL_ID, "High",
|
||||
NotificationManager.IMPORTANCE_HIGH)
|
||||
highChannel.description = "Tells about incoming call or message"
|
||||
highChannel.lockscreenVisibility = Notification.VISIBILITY_PUBLIC
|
||||
highChannel.enableVibration(true)
|
||||
nm.createNotificationChannel(highChannel)
|
||||
}
|
||||
}
|
||||
|
||||
private fun showStatusNotification() {
|
||||
snb.setVisibility(VISIBILITY_PUBLIC)
|
||||
.setSmallIcon(R.drawable.ic_stat)
|
||||
.setContentIntent(npi)
|
||||
.setPriority(NotificationManager.IMPORTANCE_HIGH)
|
||||
.setOngoing(true)
|
||||
.setContent(RemoteViews(packageName, R.layout.status_notification))
|
||||
if (RUN_FOREGROUNG)
|
||||
@ -195,7 +210,7 @@ class BaresipService: Service() {
|
||||
intent.putExtra("uap", uap)
|
||||
intent.putExtra("callp", "")
|
||||
LocalBroadcastManager.getInstance(this).sendBroadcast(intent)
|
||||
updateNotification()
|
||||
updateStatusNotification()
|
||||
}
|
||||
|
||||
@Keep
|
||||
@ -219,17 +234,17 @@ class BaresipService: Service() {
|
||||
MainActivity.images[account_index] = R.drawable.dot_yellow
|
||||
else
|
||||
MainActivity.images[account_index] = R.drawable.dot_green
|
||||
updateNotification()
|
||||
updateStatusNotification()
|
||||
if (!Utils.isVisible()) return
|
||||
}
|
||||
"registering failed" -> {
|
||||
MainActivity.images[account_index] = R.drawable.dot_red
|
||||
updateNotification()
|
||||
updateStatusNotification()
|
||||
if (!Utils.isVisible()) return
|
||||
}
|
||||
"unregistering" -> {
|
||||
MainActivity.images[account_index] = R.drawable.dot_yellow
|
||||
updateNotification()
|
||||
updateStatusNotification()
|
||||
if (!Utils.isVisible()) return
|
||||
}
|
||||
"call ringing" -> {
|
||||
@ -237,15 +252,20 @@ class BaresipService: Service() {
|
||||
}
|
||||
"call incoming" -> {
|
||||
if (!Utils.isVisible()) {
|
||||
snb.setVibrate(LongArray(0))
|
||||
val view = RemoteViews(getPackageName(), R.layout.status_notification)
|
||||
cnb.setVisibility(VISIBILITY_PUBLIC)
|
||||
.setSmallIcon(R.drawable.ic_stat)
|
||||
.setContentIntent(npi)
|
||||
.setAutoCancel(true)
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
|
||||
cnb.setVibrate(LongArray(0))
|
||||
.setPriority(Notification.PRIORITY_HIGH)
|
||||
}
|
||||
val view = RemoteViews(getPackageName(), R.layout.call_notification)
|
||||
view.setTextViewText(R.id.callFrom, "Call from ${Api.call_peeruri(callp)}")
|
||||
view.setViewVisibility(R.id.callFrom, View.VISIBLE)
|
||||
snb.setContent(view)
|
||||
nm.notify(STATUS_NOTIFICATION_ID, snb.build())
|
||||
cnb.setContent(view)
|
||||
nm.notify(CALL_NOTIFICATION_ID, cnb.build())
|
||||
}
|
||||
/* if (!Utils.isVisible()) {
|
||||
nm.cancel(STATUS_NOTIFICATION_ID)
|
||||
val cnb = NotificationCompat.Builder(this)
|
||||
.setSmallIcon(R.drawable.ic_stat)
|
||||
.setContentIntent(npi)
|
||||
@ -280,11 +300,6 @@ class BaresipService: Service() {
|
||||
}
|
||||
"call established", "call closed" -> {
|
||||
nm.cancel(CALL_NOTIFICATION_ID)
|
||||
val view = RemoteViews(getPackageName(), R.layout.status_notification)
|
||||
view.setViewVisibility(R.id.callFrom, View.GONE)
|
||||
snb.setContent(view)
|
||||
snb.setVibrate(null)
|
||||
nm.notify(STATUS_NOTIFICATION_ID, snb.build())
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -296,7 +311,7 @@ class BaresipService: Service() {
|
||||
LocalBroadcastManager.getInstance(this).sendBroadcast(intent)
|
||||
}
|
||||
|
||||
private fun updateNotification() {
|
||||
private fun updateStatusNotification() {
|
||||
val contentView = RemoteViews(getPackageName(), R.layout.status_notification)
|
||||
for (i: Int in 0 .. 5) {
|
||||
val resID = resources.getIdentifier("status$i", "id", packageName)
|
||||
@ -335,7 +350,9 @@ class BaresipService: Service() {
|
||||
|
||||
var IS_SERVICE_RUNNING = false
|
||||
val STATUS_NOTIFICATION_ID = 101
|
||||
val DEFAULT_CHANNEL_ID = "com.tutpro.baresip.default"
|
||||
val CALL_NOTIFICATION_ID = 102
|
||||
val HIGH_CHANNEL_ID = "com.tutpro.baresip.high"
|
||||
var disconnected = false
|
||||
val RUN_FOREGROUNG = false
|
||||
|
||||
|
||||
@ -974,7 +974,5 @@ class MainActivity : AppCompatActivity() {
|
||||
const val HISTORY_SIZE = 100
|
||||
const val ONE_CALL_ONLY = true
|
||||
|
||||
const val INCOMING_ID = 102
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,49 +1,51 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/notificationLayout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical" >
|
||||
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/callHeading"
|
||||
android:id="@+id/mainRow"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="14dp"
|
||||
android:layout_marginBottom="10dp"
|
||||
android:orientation="horizontal" >
|
||||
|
||||
<ImageView android:id="@+id/headingImage"
|
||||
<ImageView android:id="@+id/image"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:paddingStart="10dp"
|
||||
android:paddingEnd="5dp"
|
||||
android:paddingLeft="10dp"
|
||||
android:paddingRight="5dp"
|
||||
android:src="@drawable/baresip" />
|
||||
|
||||
<TextView android:id="@+id/headingText"
|
||||
<TextView android:id="@+id/text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:textSize="15dp"
|
||||
android:textColor="#000000"
|
||||
android:text="Call from"
|
||||
android:text="Baresip "
|
||||
style = "@android:style/TextAppearance.Medium" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<TextView android:id="@+id/caller"
|
||||
<TextView android:id="@+id/callFrom"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="20dp"
|
||||
android:layout_below="@id/callHeading"
|
||||
android:layout_below="@id/mainRow"
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_marginLeft="16dp"
|
||||
android:layout_marginBottom="10dp"
|
||||
android:textSize="15dp"
|
||||
android:text="peer uri"
|
||||
style = "@android:style/TextAppearance.Medium" />
|
||||
|
||||
<!--
|
||||
<Button android:id="@+id/answerButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/caller"
|
||||
android:layout_below="@id/callFrom"
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_marginBottom="14dp"
|
||||
android:layout_marginStart="16dp"
|
||||
@ -53,12 +55,13 @@
|
||||
<Button android:id="@+id/rejectButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/caller"
|
||||
android:layout_below="@id/callFrom"
|
||||
android:layout_toEndOf="@id/answerButton"
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_marginBottom="14dp"
|
||||
android:layout_marginStart="20dp"
|
||||
android:layout_gravity="center"
|
||||
android:text="Reject" />
|
||||
|
||||
-->
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
@ -1,79 +1,60 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/notificationLayout"
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/mainRow"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical" >
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal" >
|
||||
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/mainRow"
|
||||
android:layout_width="match_parent"
|
||||
<ImageView android:id="@+id/image"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="14dp"
|
||||
android:orientation="horizontal" >
|
||||
android:layout_gravity="center"
|
||||
android:paddingLeft="10dp"
|
||||
android:paddingRight="5dp"
|
||||
android:src="@drawable/baresip" />
|
||||
|
||||
<ImageView android:id="@+id/image"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:paddingLeft="10dp"
|
||||
android:paddingRight="5dp"
|
||||
android:src="@drawable/baresip" />
|
||||
|
||||
<TextView android:id="@+id/text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:textSize="15dp"
|
||||
android:textColor="#000000"
|
||||
android:text="Baresip "
|
||||
style = "@android:style/TextAppearance.Medium" />
|
||||
|
||||
<ImageView android:id="@+id/status0"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:paddingLeft="10dp" />
|
||||
|
||||
<ImageView android:id="@+id/status1"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:paddingLeft="10dp" />
|
||||
|
||||
<ImageView android:id="@+id/status2"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:paddingLeft="10dp" />
|
||||
|
||||
<ImageView android:id="@+id/status3"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:paddingLeft="10dp" />
|
||||
|
||||
<TextView android:id="@+id/etc"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:paddingLeft="5dp"
|
||||
android:text="..."
|
||||
android:textColor="#000000"
|
||||
style = "@android:style/TextAppearance.Medium" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<TextView android:id="@+id/callFrom"
|
||||
android:layout_width="match_parent"
|
||||
<TextView android:id="@+id/text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/mainRow"
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_marginLeft="16dp"
|
||||
android:layout_marginBottom="10dp"
|
||||
android:layout_gravity="center"
|
||||
android:textSize="15dp"
|
||||
android:text="Call from"
|
||||
android:visibility="gone"
|
||||
android:textColor="#000000"
|
||||
android:text="Baresip "
|
||||
style = "@android:style/TextAppearance.Medium" />
|
||||
|
||||
</RelativeLayout>
|
||||
<ImageView android:id="@+id/status0"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:paddingLeft="10dp" />
|
||||
|
||||
<ImageView android:id="@+id/status1"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:paddingLeft="10dp" />
|
||||
|
||||
<ImageView android:id="@+id/status2"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:paddingLeft="10dp" />
|
||||
|
||||
<ImageView android:id="@+id/status3"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:paddingLeft="10dp" />
|
||||
|
||||
<TextView android:id="@+id/etc"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginBottom="14dp"
|
||||
android:paddingLeft="5dp"
|
||||
android:text="..."
|
||||
android:textColor="#000000"
|
||||
style = "@android:style/TextAppearance.Medium" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user