Home > Mobile >  is it possible to get activity in TileService?
is it possible to get activity in TileService?

Time:10-22

Im trying to launch a method from the onClick method on TileService , but my method require the activity object , i didn't figure out how to get it on TileService


@RequiresApi(Build.VERSION_CODES.N)
class TileService:TileService() {
    val TAG ="Tile"


 
    // Called when the user taps on your tile in an active or inactive state.
    override fun onClick() {
        super.onClick()
        Log.d(TAG, "onClick: ")
        Toast.makeText(application, "hello world", Toast.LENGTH_SHORT).show()

        AppHelper.getInstance().startMethod("Here i need activity object ")

    }
    // Called when the user removes your tile.
    override fun onTileRemoved() {
        super.onTileRemoved()
        Log.d(TAG, "onTileRemoved: ")
    }

}

CodePudding user response:

Im trying to launch a method from the onClick method on TileService , but my method require the activity object , i didn't figure out how to get it on TileService

There may not be an Activity object. There is no requirement for you to have a running process at the time the user clicks on your tile.

I am using Media Projection Api , for exemple the startActivityForResult needs the activity

You probably can call startActivity() from a tile. So, call startActivity() for some activity of yours, and that can call startActivityForResult() to start the media projection confirmation dialog.

  • Related