当USB设备连接到Android平板电脑时,会出现一个弹出窗口,要求获得用户许可.我想压制这个,因为客户端不想要它.我该怎么办呢?
在代码中:
UsbManager.requestpermission();
Run Code Online (Sandbox Code Playgroud)
被调用以给USB设备临时访问.
这会弹出一个弹出窗口.默认情况下,如何禁止弹出窗口或授予用户访问权限?
我需要根据一些运行时信息在启动器中隐藏或显示我的应用程序图标.我仍然希望能够以明确的意图运行活动,因此禁用活动不是一个好的选择(我甚至不知道它是否会起作用,我还没有尝试过,但是我猜它会).那么,我可以禁用意图过滤器吗?
在我的活动中,我有一个Web视图,在manifest.xml中,我已经声明了这样的intent过滤器
<activity
android:name=".ui.socialNetwork.MySocialNetworkActivity"
android:configChanges="orientation|screenSize"
android:process=":fb"
android:screenOrientation="portrait" >
</activity>
<activity-alias
android:targetActivity=".ui.socialNetwork.MySocialNetworkActivity"
android:name=".AliasMySocialNetworkActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.PROCESS_TEXT" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
</activity-alias>
Run Code Online (Sandbox Code Playgroud)
这不是发射器活动.这里使用的intent过滤器用于Web视图上的复制粘贴工具栏长按.这很好用.除此之外,我想使用Webview.setOnLongClickListener()获取其他选项,我实现了这样.
webView = (WebView) findViewById(R.id.webview);
PackageManager pm = getApplicationContext().getPackageManager();
ComponentName compName =
new ComponentName(getPackageName(), getPackageName() + ".AliasMySocialNetworkActivity");
pm.setComponentEnabledSetting(
compName,
PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
PackageManager.DONT_KILL_APP);
webView.setOnLongClickListener(new View.OnLongClickListener() {
public boolean onLongClick(View v) {
WebView.HitTestResult hitResult = null;
hitResult = webView.getHitTestResult();
if (hitResult != null && hitResult.getExtra() != null) {
final String hitRes = hitResult.getExtra();
if (hitResult.getType() == WebView.HitTestResult.IMAGE_TYPE || hitResult.getType() …Run Code Online (Sandbox Code Playgroud) 我试图阻止我正在处理的应用程序每次USB设备断开时都要求USB权限.我跟着:USB设备访问弹出抑制?没有太多运气.
该应用确实记住USB设备,直到设备被拔掉.
如果重要,我正在尝试将应用程序连接到Arduino Teensy.
这就是我的清单活动的样子
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter> <!-- For receiving data from another application -->
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
<intent-filter>
<action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"/>
</intent-filter>
<meta-data android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" android:resource="@xml/usb_device_filter" />
</activity>
</application>
Run Code Online (Sandbox Code Playgroud)
这是我的usb_device_filter文件:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<usb-device vendor-id="--hidden--" product-id="--hidden--" />
</resources>
Run Code Online (Sandbox Code Playgroud)
欢迎任何帮助.
编辑:我也查看Android Developer页面,他们说当使用意图过滤器进行USB连接时:如果用户接受,您的应用程序将自动拥有访问设备的权限,直到设备断开连接.
我还想指出,建议的副本与我试图解决的问题不同.他们的问题是有两个活动,而我的问题只涉及一个.
https://developer.android.com/guide/topics/connectivity/usb/host