After downloading Cortana, it lets you set as the default device assist app. The app does that by firing up the specific settings page via intent. So, what is the specific intent for doing so?
I have asked the same question to many forums, but I got the same answer- It is not possible... Turns out, it is.
Dim i As Intent
i.Initialize("android.settings.VOICE_INPUT_SETTINGS", "")
i.SetComponent("com.android.settings/com.android.settings.Settings$ManageAssistActivity")
StartActivity(i)
Note that it is better to post smaller images. The large images makes it difficult to understand the post.
Try this:
B4X:
Dim p As Phone
Dim Assistant As String = p.GetSetting("voice_interaction_service")
Log(Assistant)
Dim IsDefaultAssistant As Boolean = Assistant.Contains(App.PackageName)
When the default is set to my app, it returns nothing. But when Google assistant is set, it returns: com.google.android.googlequicksearchbox/com.google.android.voiceinteraction.GsaVoiceInteractionService
'For launching the app on long pressing home button
AddActivityText(Main,
<intent-filter>
<meta-data android:name="com.android.systemui.action_assist_icon"
android:icon="@drawable/ic_action_assist" />
android:resource="@drawable/ic_action_assist" />
<action android:name="android.intent.action.ASSIST" />
<category android:name="android.intent.category.DEFAULT">
</category>
</intent-filter>)
Where main is the activity to launch at the long press of home button.
Add the following to activity create:
B4X:
Sub Activity_Create(FirstTime As Boolean)
If FirstTime then
Dim r As Reflector
If r.GetStaticField("android.os.Build$VERSION", "SDK_INT")>22 Then 'IF API>22 THEN
Dim p As Phone
Log(p.GetSettings("voice_interaction_service"))
If p.GetSettings("voice_interaction_service")="com.google.android.googlequicksearchbox/com.google.android.voiceinteraction.GsaVoiceInteractionService" Then SetDefaultAssistant 'If the Default is Google Assistant
Else 'IF API<22 FOR DEVICES RUNNING LESS THAN MARSHMALLOW
Msgbox("Long press home button and select '<YOU APP NAME>'", "Set your default Assistant")
End If
End If
End Sub
B4X:
Sub SetDefaultAssistant
Try
Msgbox("Tap 'Assist app' in the next screen, and choose '<Your App Name>'", "Set your default Assistant")
Dim i As Intent
i.Initialize("android.settings.VOICE_INPUT_SETTINGS", "")
i.SetComponent("com.android.settings/com.android.settings.Settings$ManageAssistActivity")
StartActivity(i)
Catch
Log(LastException)
End Try
End Sub
In the above Example, I set a different Transparent Activity named"Assist" as the default.