2

我正在尝试将谷歌助手实现到我自己的安卓应用程序中,我一直在关注谷歌示例上的操作:https ://github.com/actions-on-google/appactions-fitness-kotlin/issues/9 。

我正进入(状态

java.lang.SecurityException:调用者必须拥有内容://at.oeamtc.android.oeamtclib.MySliceProvider

这是它崩溃的部分,在

SliceManager.getInstance(context) .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;
}
4

0 回答 0