-
-
Notifications
You must be signed in to change notification settings - Fork 326
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #568 from lollipopkit/lollipopkit/issue564
- Loading branch information
Showing
18 changed files
with
344 additions
and
202 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
android/app/src/main/kotlin/tech/lolli/toolbox/ForegroundService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package tech.lolli.toolbox | ||
|
||
import android.app.* | ||
import android.content.Intent | ||
import android.os.Build | ||
import android.os.IBinder | ||
|
||
class ForegroundService : Service() { | ||
private val chanId = "ForegroundServiceChannel" | ||
|
||
override fun onCreate() { | ||
super.onCreate() | ||
createNotificationChannel() | ||
} | ||
|
||
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { | ||
val notification = createNotification() | ||
startForeground(1, notification) | ||
|
||
// Exec your code here | ||
|
||
return START_STICKY | ||
} | ||
|
||
override fun onBind(intent: Intent): IBinder? { | ||
return null | ||
} | ||
|
||
private fun createNotificationChannel() { | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { | ||
val serviceChannel = NotificationChannel( | ||
chanId, | ||
chanId, | ||
NotificationManager.IMPORTANCE_DEFAULT | ||
) | ||
val manager = getSystemService(NotificationManager::class.java) | ||
manager.createNotificationChannel(serviceChannel) | ||
} | ||
} | ||
|
||
private fun createNotification(): Notification { | ||
val notificationIntent = Intent(this, MainActivity::class.java) | ||
val pendingIntent = PendingIntent.getActivity( | ||
this, | ||
0, | ||
notificationIntent, | ||
PendingIntent.FLAG_IMMUTABLE | ||
) | ||
|
||
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { | ||
Notification.Builder(this, chanId) | ||
.setContentTitle("App is running") | ||
.setContentText("Click to open the app") | ||
.setSmallIcon(R.mipmap.ic_launcher) | ||
.setContentIntent(pendingIntent) | ||
.build() | ||
} else { | ||
Notification.Builder(this) | ||
.setContentTitle("App is running") | ||
.setContentText("Click to open the app") | ||
.setSmallIcon(R.mipmap.ic_launcher) | ||
.setContentIntent(pendingIntent) | ||
.build() | ||
} | ||
} | ||
} |
18 changes: 0 additions & 18 deletions
18
android/app/src/main/kotlin/tech/lolli/toolbox/KeepAliveService.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.