Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,5 @@
</intent-filter>
</service>

</application>

</application>
</manifest>
27 changes: 19 additions & 8 deletions app/src/main/java/com/darkempire78/opencalculator/MyTileService.kt
Original file line number Diff line number Diff line change
@@ -1,22 +1,33 @@
package com.darkempire78.opencalculator

import android.app.PendingIntent
import android.content.Intent
import android.content.Intent.FLAG_ACTIVITY_NEW_TASK
import android.graphics.drawable.Icon
import android.os.Build
import android.service.quicksettings.Tile
import android.service.quicksettings.TileService
import androidx.annotation.RequiresApi

@RequiresApi(Build.VERSION_CODES.N)
class MyTileService: TileService() {
class MyTileService : TileService() {

// Called when the user taps on your tile in an active or inactive state.
override fun onClick() {
super.onClick()

// Intent to launch MainActivity
val intent = Intent(this, MainActivity::class.java)
.addFlags(FLAG_ACTIVITY_NEW_TASK)
// Create a PendingIntent from the intent
val pendingIntent = PendingIntent.getActivity(
this,
0,
intent,
PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT
)

startActivityAndCollapse(intent)
// Check the SDK version to determine which method to use
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
startActivityAndCollapse(pendingIntent)
} else {
// For older versions, convert PendingIntent to Intent and start the activity
val newIntent = Intent(intent).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
startActivity(newIntent)
}
}
}