try to run at boot
This commit is contained in:
parent
5c235b3e56
commit
3e841f9df9
Binary file not shown.
Binary file not shown.
@ -2,9 +2,11 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
|
||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
||||
|
||||
<application
|
||||
android:name=".CatFlipScreenApplication"
|
||||
android:allowBackup="true"
|
||||
android:dataExtractionRules="@xml/data_extraction_rules"
|
||||
android:fullBackupContent="@xml/backup_rules"
|
||||
@ -26,7 +28,7 @@
|
||||
<service
|
||||
android:name=".FlipScreenService"
|
||||
android:enabled="true"
|
||||
android:exported="false" />
|
||||
android:exported="true" />
|
||||
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
|
@ -0,0 +1,31 @@
|
||||
package net.mezimmah.catflipscreen
|
||||
|
||||
import android.app.Application
|
||||
import android.app.NotificationChannel
|
||||
import android.app.NotificationManager
|
||||
|
||||
|
||||
class CatFlipScreenApplication : Application() {
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
createNotificationChannel()
|
||||
}
|
||||
|
||||
private fun createNotificationChannel() {
|
||||
val serviceChannel = NotificationChannel(
|
||||
CHANNEL_ID,
|
||||
CHANNEL_NAME,
|
||||
NotificationManager.IMPORTANCE_DEFAULT
|
||||
)
|
||||
val manager = getSystemService(
|
||||
NotificationManager::class.java
|
||||
)
|
||||
manager.createNotificationChannel(serviceChannel)
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val CHANNEL_ID = "autoStartServiceChannel"
|
||||
const val CHANNEL_NAME = "Auto Start Service Channel"
|
||||
}
|
||||
|
||||
}
|
@ -1,24 +1,55 @@
|
||||
package net.mezimmah.catflipscreen
|
||||
|
||||
import android.app.Notification
|
||||
import android.app.NotificationChannel
|
||||
import android.app.NotificationManager
|
||||
import android.app.PendingIntent
|
||||
import android.app.Service
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.media.MediaRouter
|
||||
import android.os.IBinder
|
||||
import android.util.Log
|
||||
import androidx.core.app.NotificationCompat
|
||||
|
||||
|
||||
class FlipScreenService : Service() {
|
||||
|
||||
override fun onBind(intent: Intent): IBinder {
|
||||
override fun onBind(intent: Intent): IBinder? {
|
||||
TODO("Return the communication channel to the service.")
|
||||
}
|
||||
|
||||
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
||||
showNotification(intent)
|
||||
showPresentationScreen()
|
||||
|
||||
return super.onStartCommand(intent, flags, startId)
|
||||
}
|
||||
|
||||
private fun showNotification(intent: Intent?) {
|
||||
val input: String? = intent?.getStringExtra("inputExtra")
|
||||
val notificationIntent = Intent(this, MainActivity::class.java)
|
||||
val pendingIntent = PendingIntent.getActivity(
|
||||
this,
|
||||
0, notificationIntent, PendingIntent.FLAG_IMMUTABLE
|
||||
)
|
||||
val notification: Notification = NotificationCompat.Builder(this, CatFlipScreenApplication.CHANNEL_ID)
|
||||
.setContentTitle("Auto Start Service")
|
||||
.setContentText(input)
|
||||
.setSmallIcon(android.R.drawable.ic_dialog_info)
|
||||
.setContentIntent(pendingIntent)
|
||||
.build()
|
||||
val mNotificationManager = getSystemService(NOTIFICATION_SERVICE) as NotificationManager
|
||||
val channel = NotificationChannel(
|
||||
CatFlipScreenApplication.CHANNEL_ID,
|
||||
CatFlipScreenApplication.CHANNEL_NAME,
|
||||
NotificationManager.IMPORTANCE_DEFAULT
|
||||
)
|
||||
mNotificationManager.createNotificationChannel(channel)
|
||||
NotificationCompat.Builder(this, CatFlipScreenApplication.CHANNEL_ID)
|
||||
startForeground(1, notification)
|
||||
}
|
||||
|
||||
private fun showPresentationScreen() {
|
||||
try {
|
||||
val selectedRoute =
|
||||
|
Loading…
x
Reference in New Issue
Block a user