求通过Intent设置默认设备助手应用的具体Intent参数(Cortana可用)
Hey there, I totally get your frustration—this is one of those under-documented Intent workflows that most forums brush off as impossible, but it is doable, especially if you understand how Android handles default assistant settings. Let me break down what works:
1. Launch the System Assistant Settings Page (No Special Permissions)
The most reliable, user-facing way is to open the system's built-in settings page where users can select Cortana as their default assistant. This doesn't require any special permissions and works on all Android versions:
For Kotlin:
val intent = Intent(Settings.ACTION_VOICE_INPUT_SETTINGS) intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK context.startActivity(intent)
For Java:
Intent intent = new Intent(Settings.ACTION_VOICE_INPUT_SETTINGS); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent);
This will take the user straight to the screen where they can pick Cortana from the list of available assistants.
2. Directly Set Cortana as Default (Requires System Privileges)
If you're working with a system-level app (like preloaded software), you can skip the user selection and set Cortana directly. This needs the WRITE_SECURE_SETTINGS permission, which is only granted to apps signed with the platform key or system-privileged apps.
First, declare the permission in your manifest:
<uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" />
Then use this code to update the default assistant:
val cortanaPackage = "com.microsoft.cortana" // Double-check the package name for your region Settings.Secure.putString( context.contentResolver, Settings.Secure.DEFAULT_ASSISTANT, cortanaPackage )
A Quick Note
If you've seen Cortana do this automatically on some devices, it's almost certainly using the second method—since Microsoft often preloads it as a system app on partner devices, giving it access to those restricted permissions. For regular third-party apps, the first method is your only valid option, as Android blocks direct changes to default assistants for privacy and security.
内容的提问来源于stack exchange,提问作者Praharsh Bhatt

