Created
August 30, 2022 09:48
-
-
Save g123k/03086ab0b98e7d93d0fa4c9a04eacf2d to your computer and use it in GitHub Desktop.
Demander l'ajout d'une tuile sur Android 13 (API 33+)
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
<service | |
android:name=".MyAwesomeTile" | |
android:exported="true" | |
android:icon="@drawable/ic_launcher_foreground" | |
android:label="@string/tile_label" | |
android:permission="android.permission.BIND_QUICK_SETTINGS_TILE"> | |
<intent-filter> | |
<action android:name="android.service.quicksettings.action.QS_TILE" /> | |
</intent-filter> | |
</service> |
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
class MainActivity : AppCompatActivity() { | |
@SuppressLint("UnsafeOptInUsageError") | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_main) | |
findViewById<Button>(R.id.button1).setOnClickListener { | |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { | |
(getSystemService(Context.STATUS_BAR_SERVICE) as StatusBarManager?)?.let { | |
it.requestAddTileService( | |
ComponentName(this, MyAwesomeTile::class.java), | |
"My Awesome Tile 123", | |
Icon.createWithResource(this, R.drawable.ic_launcher_foreground), | |
{ | |
Toast.makeText(this, "Executor", Toast.LENGTH_LONG).show() | |
}, | |
) { res -> | |
Toast.makeText(this, "Result: $res", Toast.LENGTH_LONG).show() | |
} | |
} | |
} | |
} | |
} | |
} |
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
package com.emarquez.devcafe | |
import android.content.Intent | |
import android.os.Build | |
import android.service.quicksettings.Tile | |
import android.service.quicksettings.TileService | |
import androidx.annotation.RequiresApi | |
@RequiresApi(Build.VERSION_CODES.N) | |
class MyAwesomeTile : TileService() { | |
override fun onStartListening() { | |
super.onStartListening() | |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { | |
qsTile.subtitle = "Hello World" | |
} | |
qsTile.state = Tile.STATE_ACTIVE | |
qsTile.updateTile() | |
} | |
override fun onClick() { | |
super.onClick() | |
val intent = Intent(this, MainActivity::class.java).apply { | |
flags += Intent.FLAG_ACTIVITY_NEW_TASK | |
} | |
startActivityAndCollapse(intent) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment