![](/img/trans.png)
[英]React Native app won't build for Android on USB or in APK form, but builds fine in emulator
[英]Android App Won't Remember USB Permission
我試圖阻止我正在處理的應用程序每次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>
這是我的usb_device_filter文件:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<usb-device vendor-id="--hidden--" product-id="--hidden--" />
</resources>
歡迎任何幫助。
編輯:我也查看Android Developer頁面,他們說當使用意圖過濾器進行USB連接時: 如果用戶接受,您的應用程序將自動擁有訪問設備的權限,直到設備斷開連接。
我還想指出,建議的副本與我試圖解決的問題不同。 他們的問題是有兩個活動,而我的問題只涉及一個。
https://developer.android.com/guide/topics/connectivity/usb/host
當USB插入手機時,我們最終自動打開應用程序,因為我們的項目處理應用程序全天開放。
只要用戶在打開應用程序之前連接USB並且手機已解鎖,該應用程序僅要求允許一次使用USB進行手機並立即記住。 電話重啟后,手機甚至會記住該許可。
這是一種解決方法,但它可以滿足我們的需求。 希望這可以幫助其他人解決同樣的問題。
正如這里的提問者所說,為了你的意圖(如果我理解正確的話),以下內容應該足夠了。 這是正確的,他有一個不同的問題,但他開始他的問題說,為你的情況,它的工作。
<activity android:name=".FirstActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.