my phone installed two voice searches: google app and S-voice app. The default app is S-voice app as figure bellow. My question is that how can we get the default voice application using programmingcally in Android 6.0. Thank you in advance
This is what I did
private boolean isMyAppLauncherDefault(String myPackageName) {
final IntentFilter filter = new IntentFilter(Intent.ACTION_MAIN);
filter.addCategory(Intent.CATEGORY_HOME);
List<IntentFilter> filters = new ArrayList<IntentFilter>();
filters.add(filter);
List<ComponentName> activities = new ArrayList<ComponentName>();
final PackageManager packageManager = (PackageManager) getPackageManager();
packageManager.getPreferredActivities(filters, activities, null);
for (ComponentName activity : activities) {
Log.d(TAG,"======packet default:==="+activity.getPackageName());
}
for (ComponentName activity : activities) {
if (myPackageName.equals(activity.getPackageName())) {
return true;
}
}
return false;
}
The above function is alway return true when my input is com.samsung.voiceserviceplatform
. In other hands, the default app always returns com.google.android.googlequicksearchbox
(indicates google voice)
I try answer from Mattia Maestrini, it did work if returned component is an activity, like
but if the component is a service, I meet following problem
and I do add
in Manifest file.
At last I use method in Activity.java
It's added from Android M and it could start assistant service successfully.
The
DefaultAssistPreference
uses an hidden method ofAssistUtils
to retrieve the current Assist. You can use the same method using reflection:If you don't want to use reflection you can directly check the system settings:
It is the same setting that reads
AssistUtils
, butAssistUtils
has also a fallback if the setting is not valid.Try this.