I want to pop up a dialog that lets the user choose a launcher to be launched with set as default option. I tried
Intent home = new Intent(
Starting from API 29 this is now officially supported using RoleManager.
A very simple Kotlin example of a method you can call from any activity:
fun showLauncherSelector(activity: AppCompatActivity, requestCode : Int) {
val roleManager = activity.getSystemService(Context.ROLE_SERVICE) as RoleManager
if(roleManager.isRoleAvailable(RoleManager.ROLE_HOME)){
val intent = roleManager.createRequestRoleIntent(RoleManager.ROLE_HOME)
activity.startActivityForResult(intent, requestCode)
}
}
Then you can check for errors in the caller activity:
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
if (requestCode == MY_REQUEST_CODE) {
if (resultCode != Activity.RESULT_OK) {
// Something went wrong
}
}
}