goR*_*Gon 9 android google-now android-6.0-marshmallow google-assist-api
Google最近发布了具有Now on Tap的Android Marshmallow,可以扫描应用内容并向用户提供其他信息.
不幸的是,我们的应用程序的信息看起来并不十分相关和谷歌无视我们的内部设置数据onProvideContentAssist()和onProvideAssistData().
这些规格看起来相当高,并且还包含" 可以建议 "和" 附加信息 "等词语,因此Google似乎正式允许自己忽略开发人员提供的数据.
所以我们决定禁用Now on Tap,但似乎并不是非常简单.根据上面提供的文件,我们应该FLAG_SECURE在这种情况下使用.但随后用户无法捕获屏幕截图,Google Now on Tap开始以下面面向用户的消息来指责我们的应用:
结果不可用
此应用已阻止Now on Tap
但似乎Opera在某种程度上轻轻地阻止了Now on Tap的私人标签.它为他们显示了更多app友好的消息:
什么都没有
Opera如何阻止现在点击?
有没有人知道如何阻止Google Assist API(现在点击)而不会对我们的应用程序负责?
View类有一个方法setAssistBlocked:
控制是否启用此视图及其子项的辅助数据收集(即,是否将调用{@link #onProvideStructure}和{@link #onProvideVirtualStructure}).默认值为false,允许正常辅助收集.将此设置为false将禁用辅助收集.
@param enabled设置为true以禁用辅助数据收集,或设置为false(默认值)以允许它.
不幸的是这个方法有注释@hide,所以我们看不到或直接使用它.
但我们可以通过一个小的反射调用来使用它:
private void setAssistBlocked(View view, boolean blocked) {
try {
Method setAssistBlockedMethod = View.class.getMethod("setAssistBlocked", boolean.class);
setAssistBlockedMethod.invoke(view, blocked);
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
Run Code Online (Sandbox Code Playgroud)
要阻止您可以使用的活动中的所有内容:
final View rootContent = findViewById(android.R.id.content);
setAssistBlocked(rootContent, true);
Run Code Online (Sandbox Code Playgroud)
我最终需要尝试的另一个可能的解决方案是hackbod的一条评论暗示:
此外,在这种情况下,没有理由这样做,因为你可以使用它:https://developer.android.com/reference/android/view/View.html#dispatchProvideStructure(android.view.ViewStructure)
状态的代码注释dispatchProvideStructure():" 在层次结构中调度创建ViewStructure ".(强调我的).
因此,创建一个NoAssistFrameLayout子类FrameLayout,覆盖dispatchProvideStructure()为无操作,并将其用作活动布局的根容器.这将阻止自动填充ViewStructure活动体内任何事物.
但是,它不会阻止任何可以从主要内容区域之外的内容推断出来的内容,例如操作栏,因为它将位于NoAssistFrameLayout视图层次结构之外.可能没有多少会产生隐私影响,但这是这种技术的局限.
好的,我已经尝试过了,它似乎确实有效:
/***
Copyright (c) 2015 CommonsWare, LLC
Licensed under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License. You may obtain a copy
of the License at http://www.apache.org/licenses/LICENSE-2.0. Unless required
by applicable law or agreed to in writing, software distributed under the
License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
OF ANY KIND, either express or implied. See the License for the specific
language governing permissions and limitations under the License.
From _The Busy Coder's Guide to Android Development_
https://commonsware.com/Android
*/
package com.commonsware.android.assist.no;
import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.util.AttributeSet;
import android.view.ViewStructure;
import android.widget.FrameLayout;
public class NoAssistFrameLayout extends FrameLayout {
public NoAssistFrameLayout(Context context) {
super(context);
}
public NoAssistFrameLayout(Context context,
AttributeSet attrs) {
super(context, attrs);
}
public NoAssistFrameLayout(Context context,
AttributeSet attrs,
int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public NoAssistFrameLayout(Context context,
AttributeSet attrs,
int defStyleAttr,
int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
@Override
public void dispatchProvideStructure(ViewStructure structure) {
// no, thanks
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2536 次 |
| 最近记录: |