简体   繁体   English

如何通过 Intent 在设置中打开 android 默认应用程序活动?

[英]How to open android default apps activity in setting via Intent?

How to open the default handler page in the android setting via intent?如何通过 Intent 打开 android 设置中的默认处理程序页面? or How we can open directly the default SMS page?或者我们如何才能直接打开默认的短信页面?

在此处输入图像描述

it seems from android Q to upper we can not Telephony.Sms.Intents.ACTION_CHANGE_DEFAULT似乎从 android Q 到上层我们不能Telephony.Sms.Intents.ACTION_CHANGE_DEFAULT

Found the answer, you can open this page by this code:找到答案,您可以通过以下代码打开此页面:

//This code will work only on android version N and above
//Add if condition to prevent crash on older devices

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        Intent intent = new Intent(Settings.ACTION_MANAGE_DEFAULT_APPS_SETTINGS);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        if (requestCode != -1)
             act.startActivityForResult(intent, requestCode);
        else
             act.startActivity(intent);
    }

Another way with this code to open an intent default app, in this case, I try to set the default launcher app使用此代码打开意图默认应用程序的另一种方法,在这种情况下,我尝试设置默认启动器应用程序

// dialog set default app
@RequiresApi(Build.VERSION_CODES.Q)
private fun showLauncherSelection() {
    val roleManager = this.getSystemService(Context.ROLE_SERVICE)
            as RoleManager
    if (roleManager.isRoleAvailable(RoleManager.ROLE_HOME) &&
        !roleManager.isRoleHeld(RoleManager.ROLE_HOME)
    ) {
        val intent = roleManager.createRequestRoleIntent(RoleManager.ROLE_HOME)
        startActivityForResult(intent,0)
    }
}

You can set the other Default app with change the ROLE_HOME following this Role Manager .您可以在此Role Manager之后更改ROLE_HOME来设置其他默认应用程序。 If you want to change SMS default app, try to change the ROLE_HOME to ROLE_SMS如果要更改短信默认应用,请尝试将ROLE_HOME更改为ROLE_SMS

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 设置默认活动Android - Setting Default Activity Android 通过意图将图像传递给默认联系人活动 - Pass image via intent to default contacts activity 如何在Android中使用菜单从Main活动中打开Intent(MapView) - How to open an Intent (MapView) from the Main activity with menu in Android Android - 而不是对新课程/活动推出新意图,如何回到开放活动/课程? - Android - instead of launch new intent to new class/activity, how go back to open activity/class? Android,如何使用 Intent 选择器打开 UPI 支付应用程序,不适用于 Android 11 和 12 版本 - Android, how to open UPI Payment Apps using Intent chooser, not working on Android 11 and 12 versions 启动器活动的默认意图 - Default Intent for launcher Activity Android:动态创建的列表视图中的项目如何通过重用意图来打开另一个自有活动 - Android: How can items in dynamically-created listview open another self-owned activity by reusing the intent 如何从后台服务的全屏意图通知 Android 打开活动 - How to open activity from background service's full screen intent notification Android 如何通过意图将数据从当前活动发送到新活动? - How to send data to new activity from current activity via intent? 如何使用意图在主要活动布局顶部打开活动? - How to open an activity on top of the main activity layout using intent?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM