update notifications
This commit is contained in:
@@ -16,6 +16,7 @@
|
|||||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
||||||
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
|
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
|
||||||
<uses-permission android:name="android.permission.ACCESS_NOTIFICATION_POLICY" />
|
<uses-permission android:name="android.permission.ACCESS_NOTIFICATION_POLICY" />
|
||||||
|
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
|
||||||
<!-- android:icon="@mipmap/ic_launcher"-->
|
<!-- android:icon="@mipmap/ic_launcher"-->
|
||||||
<!-- android:roundIcon="@mipmap/ic_launcher_round"-->
|
<!-- android:roundIcon="@mipmap/ic_launcher_round"-->
|
||||||
<application
|
<application
|
||||||
|
|||||||
@@ -13,10 +13,16 @@ import android.os.Build
|
|||||||
import android.os.IBinder
|
import android.os.IBinder
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import androidx.annotation.RequiresApi
|
import androidx.annotation.RequiresApi
|
||||||
|
import androidx.annotation.RequiresPermission
|
||||||
|
import androidx.core.app.ActivityCompat
|
||||||
|
import androidx.core.app.NotificationCompat
|
||||||
|
import androidx.core.app.NotificationManagerCompat
|
||||||
import androidx.core.location.LocationManagerCompat
|
import androidx.core.location.LocationManagerCompat
|
||||||
|
import java.util.jar.Manifest
|
||||||
|
|
||||||
class BLEConnectionService : Service() {
|
class BLEConnectionService : Service() {
|
||||||
val CHANNEL_DEFAULT_IMPORTANCE = "1"
|
val CHANNEL_DEFAULT_IMPORTANCE = "1"
|
||||||
|
val BLE_SERVICE_ID = 111
|
||||||
val ONGOING_NOTIFICATION_ID = 2
|
val ONGOING_NOTIFICATION_ID = 2
|
||||||
var bleController: BLEController? = null
|
var bleController: BLEController? = null
|
||||||
var deviceAddress: String? = null
|
var deviceAddress: String? = null
|
||||||
@@ -57,6 +63,7 @@ class BLEConnectionService : Service() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RequiresPermission(android.Manifest.permission.POST_NOTIFICATIONS)
|
||||||
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
||||||
Log.d("DEBUG", "onStartCommand of BLE Connection Service")
|
Log.d("DEBUG", "onStartCommand of BLE Connection Service")
|
||||||
|
|
||||||
@@ -81,39 +88,37 @@ class BLEConnectionService : Service() {
|
|||||||
PendingIntent.getActivity(this, 0, notificationIntent,
|
PendingIntent.getActivity(this, 0, notificationIntent,
|
||||||
PendingIntent.FLAG_IMMUTABLE)
|
PendingIntent.FLAG_IMMUTABLE)
|
||||||
}
|
}
|
||||||
val myIntent = Intent(this, MainActivity::class.java).apply {
|
|
||||||
var flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
|
// working (before)
|
||||||
|
// val notification: Notification = Notification.Builder(this, channel_id)
|
||||||
|
// .setContentTitle("Oil-Check")
|
||||||
|
// .setContentText("running")
|
||||||
|
// .setSmallIcon(R.drawable.icon)
|
||||||
|
// .setContentIntent(serviceIntent)
|
||||||
|
// .build()
|
||||||
|
//
|
||||||
|
// startForeground(101, notification)
|
||||||
|
|
||||||
|
// new notification
|
||||||
|
// tap action
|
||||||
|
val intentActivity = Intent(this, MainActivity::class.java)
|
||||||
|
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK)
|
||||||
|
val pendingActivity: PendingIntent = PendingIntent.getActivity(this, 0, intentActivity, PendingIntent.FLAG_IMMUTABLE)
|
||||||
|
|
||||||
|
// add stop button
|
||||||
|
val buttonStop = Intent(this, BLEConnectionService::class.java).apply {
|
||||||
|
action = "STOPService"
|
||||||
}
|
}
|
||||||
|
val buttonStopPendingIntent : PendingIntent = PendingIntent.getService(this, 0, buttonStop, PendingIntent.FLAG_IMMUTABLE)
|
||||||
val activityIntent = Intent(this, MainActivity::class.java)
|
var builder = NotificationCompat.Builder(this, channel_id)
|
||||||
|
.setSmallIcon(R.drawable.draw_icon_blue)
|
||||||
// val contentIntent: PendingIntent = PendingIntent.getActivity(this, 0, myIntent, PendingIntent.FLAG_IMMUTABLE)
|
|
||||||
|
|
||||||
val contentIntent = PendingIntent.getActivity(this, 0, activityIntent, PendingIntent.FLAG_MUTABLE);
|
|
||||||
// create stop button
|
|
||||||
|
|
||||||
|
|
||||||
// val intent = Intent(this, BLEConnectionService::class.java)
|
|
||||||
// .setAction("STOPService")
|
|
||||||
// val stopIntent = PendingIntent.getBroadcast(this, 0, intent, 0)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
val notification: Notification = Notification.Builder(this, channel_id)
|
|
||||||
.setContentTitle("Oil-Check")
|
.setContentTitle("Oil-Check")
|
||||||
.setContentText("running")
|
.setContentText("running")
|
||||||
.setSmallIcon(R.drawable.icon)
|
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
|
||||||
.setContentIntent(serviceIntent)
|
.setContentIntent(pendingActivity)
|
||||||
// .setContentIntent(contentIntent)
|
.addAction(0, getString(R.string.stop), buttonStopPendingIntent)
|
||||||
// .setTicker(getText(R.string.ticker_text))
|
|
||||||
// .addAction(R.drawable.icon, "Stop", contentIntent)
|
|
||||||
.build()
|
|
||||||
|
|
||||||
startForeground(101, notification)
|
NotificationManagerCompat.from(this).notify(BLE_SERVICE_ID, builder.build())
|
||||||
|
|
||||||
// startService(Intent(this, NLService::class.java)
|
|
||||||
// .setAction("StartNLService")
|
|
||||||
// )
|
|
||||||
|
|
||||||
|
|
||||||
val nlServiceIntent: PendingIntent = Intent(this, NLService::class.java).let { notificationIntent ->
|
val nlServiceIntent: PendingIntent = Intent(this, NLService::class.java).let { notificationIntent ->
|
||||||
@@ -122,38 +127,21 @@ class BLEConnectionService : Service() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
val nlNotification: Notification = Notification.Builder(this, channel_id)
|
val nlNotification: Notification = Notification.Builder(this, channel_id)
|
||||||
.setContentTitle("Oil-Check")
|
.setContentTitle("Oil-Check2")
|
||||||
.setContentText("running")
|
.setContentText("Listener")
|
||||||
.setSmallIcon(R.drawable.icon)
|
.setSmallIcon(R.drawable.icon)
|
||||||
.setContentIntent(nlServiceIntent)
|
.setContentIntent(nlServiceIntent)
|
||||||
// .addAction(R.drawable.icon, "Stop", contentIntent)
|
|
||||||
// .setTicker(getText(R.string.ticker_text))
|
|
||||||
.build()
|
.build()
|
||||||
startForeground(101, nlNotification)
|
startForeground(101, nlNotification)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// setup notification listener
|
|
||||||
// val nlServiceIntent: PendingIntent = Intent(this, NLService::class.java).let { notificationIntent ->
|
|
||||||
// PendingIntent.getActivity(this, 0, notificationIntent,
|
|
||||||
// PendingIntent.FLAG_IMMUTABLE)
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// val nlNotification: Notification = Notification.Builder(this, channel_id)
|
|
||||||
// .setContentTitle("Oil-Check")
|
|
||||||
// .setContentText("running")
|
|
||||||
// .setSmallIcon(R.drawable.icon)
|
|
||||||
// .setContentIntent(nlServiceIntent)
|
|
||||||
//// .setTicker(getText(R.string.ticker_text))
|
|
||||||
// .build()
|
|
||||||
// startForeground(101, nlNotification)
|
|
||||||
|
|
||||||
|
|
||||||
} else if (intent?.action.equals("STOPService")){
|
} else if (intent?.action.equals("STOPService")){
|
||||||
Log.d("DEBUG", "Stopflag set")
|
Log.d("DEBUG", "Stopflag set")
|
||||||
stopForeground(true)
|
stopForeground(true)
|
||||||
stopSelfResult(101)
|
// stopSelfResult(101)
|
||||||
|
val notificationManager: NotificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||||
|
notificationManager.cancel(BLE_SERVICE_ID)
|
||||||
|
notificationManager.cancel(101)
|
||||||
|
|
||||||
stopSelf()
|
stopSelf()
|
||||||
|
|
||||||
} else if (intent?.action.equals("StartNLService")) {
|
} else if (intent?.action.equals("StartNLService")) {
|
||||||
@@ -219,6 +207,12 @@ class BLEConnectionService : Service() {
|
|||||||
service.createNotificationChannel(chan)
|
service.createNotificationChannel(chan)
|
||||||
return channelId
|
return channelId
|
||||||
}
|
}
|
||||||
|
// private fun createNotificationChannel(){
|
||||||
|
// if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){
|
||||||
|
// val name = getString(R.string.channel_name) // TODO
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
// }
|
||||||
override fun onBind(p0: Intent?): IBinder? {
|
override fun onBind(p0: Intent?): IBinder? {
|
||||||
// TODO("Not yet implemented")
|
// TODO("Not yet implemented")
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -198,7 +198,7 @@ class BLEController(ctx: Context) : BLEControllerListener{
|
|||||||
// "30:83:98:00:89:86" KTM
|
// "30:83:98:00:89:86" KTM
|
||||||
return null != (device!!.address.startsWith("94:B9:7E:C0:53:FE")
|
return null != (device!!.address.startsWith("94:B9:7E:C0:53:FE")
|
||||||
or device!!.address.startsWith("30:83:98:00:89:86")
|
or device!!.address.startsWith("30:83:98:00:89:86")
|
||||||
or device!!.address.startsWith("EC:DA:3B:BF:E2:A2"))
|
or device!!.address.startsWith("EC:DA:3B:BF:E2:A2")) // testdevice
|
||||||
|
|
||||||
}
|
}
|
||||||
private fun deviceFound(device: BluetoothDevice) {
|
private fun deviceFound(device: BluetoothDevice) {
|
||||||
|
|||||||
@@ -17,14 +17,6 @@ class MainActivity : AppCompatActivity() {
|
|||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
setContentView(R.layout.activity_main)
|
setContentView(R.layout.activity_main)
|
||||||
|
|
||||||
// var location = Location("52.3759", "9.7320")
|
|
||||||
// var calculator = SunriseSunsetCalculator(location, "GMT+0200")
|
|
||||||
//
|
|
||||||
// var sunrise = calculator.getOfficialSunsetForDate(Calendar.getInstance())
|
|
||||||
//
|
|
||||||
// Log.d("Debug", sunrise)
|
|
||||||
|
|
||||||
|
|
||||||
findViewById<Button>(R.id.btnStop)
|
findViewById<Button>(R.id.btnStop)
|
||||||
.setOnClickListener{
|
.setOnClickListener{
|
||||||
Log.d("Debug", "stop clicked")
|
Log.d("Debug", "stop clicked")
|
||||||
@@ -75,9 +67,5 @@ class MainActivity : AppCompatActivity() {
|
|||||||
Intent(this, BLEConnectionService::class.java)
|
Intent(this, BLEConnectionService::class.java)
|
||||||
.setAction("STARTService")
|
.setAction("STARTService")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
<resources>
|
<resources>
|
||||||
<string name="app_name">OilCheckKotlin</string>
|
<string name="app_name">OilCheckKotlin</string>
|
||||||
|
<string name="channel_name">Oil-Nachricht</string>
|
||||||
|
<string name="stop">Stop</string>
|
||||||
</resources>
|
</resources>
|
||||||
Reference in New Issue
Block a user