我正在尝试将Google Assistant实施到我自己的android应用中,我一直在对Google示例执行以下操作:https://github.com/actions-on-google/appactions-fitness-kotlin/issues/9。
我得到了
java.lang.SecurityException:调用者必须拥有 内容://at.oeamtc.android.oeamtclib.MySliceProvider
这是它崩溃的部分,
SliceManager.getInstance(上下文) .grantSlicePermission(assistantPackage,sliceProviderUri);
private void grantAssistantPermissions() {
Context context = getApplicationContext();
Uri sliceProviderUri =
new Uri.Builder()
.scheme(ContentResolver.SCHEME_CONTENT)
.authority(OeamtcSliceProvider.SLICE_AUTHORITY)
.build();
String assistantPackage = getAssistantPackage(context);
if (assistantPackage == null) {
return;
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
SliceManager.getInstance(context)
.grantSlicePermission(assistantPackage, sliceProviderUri);
}
}
private String getAssistantPackage(Context context) {
PackageManager packageManager = context.getPackageManager();
List<ResolveInfo> resolveInfoList = packageManager.queryIntentServices(
new Intent(VoiceInteractionService.SERVICE_INTERFACE), 0);
if (resolveInfoList.isEmpty()) {
return null;
}
return resolveInfoList.get(0).serviceInfo.packageName;
}