我有一個外部USB設備,附加到Android設備上的微型USB端口,並且所有設備上的一切工作正常,直到android棒棒糖出來。現在它不再適用於Sony Xperia Z手機。索尼Xperia Z與Android棒棒糖註冊ACTION_USB_DEVICE_ATTACHED
因此,它適用於4.0或更高(並有USB託管)的所有設備,除了索尼Xperia Z與棒棒糖(在棒棒糖之前在索尼工作正常)。
所以問題是,爲什麼它會停止在棒棒糖上工作,只能專門在Xperia Z上工作?手機上發生了一些變化,但我不知道是什麼。
這是我的註冊USB設備的設置。
清單文件
<activity
android:name="com.edgetechlabs.drinkmate_play.MainActivity"
android:windowSoftInputMode="adjustPan"
android:screenOrientation="portrait"
android:launchMode="singleTask"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"/>
<action android:name="android.hardware.usb.action.USB_DEVICE_DETACHED"/>
</intent-filter>
<meta-data android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"
android:resource="@xml/device_filter" />
<meta-data android:name="android.hardware.usb.action.USB_DEVICE_DETACHED"
android:resource="@xml/device_filter" />
</activity>
裝置篩選
在MainActivity
@Override
public void onResume() {
super.onResume();
//get the intent of the activity
Intent intent = getIntent();
String action = intent.getAction();
Log.i(TAG, "MainActivity Resumed with intent " + action);
//if the device has been plugged in
if (UsbManager.ACTION_USB_DEVICE_ATTACHED.equals(intent.getAction())) {
Log.i(TAG, "Device Attached to start app");
UsbDevice device = intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
setDeviceConnection(device);
}
}
@Override
public void onNewIntent(Intent intent) {
super.onNewIntent(intent);
Log.i(TAG, "New Intent Recieved " + intent.getAction() + " with dmPluggedIn = " + dmPluggedIn);
// whenever a new intent is received from an app re-launch due to the device being plugged in
// or an intent being manually set, set the intent of the app to it only if it was from
// a device being attached. That way, when the app goes to the background with the device still attached
// the ATTACHED intent remains (because the MAIN intent is blocked)
if (UsbManager.ACTION_USB_DEVICE_ATTACHED.equals(intent.getAction())) {
System.out.println("changing intent to usb");
setIntent(intent);
}
}
要指定它不工作的原因,它不會註冊USB_DEVICE_ATTACHED意圖(當我插入設備以啓動應用程序或在應用程序啓動時插入它時)。所有的手機都會問你剛剛插入的是什麼樣的鍵盤。我不知道有關設備本身的問題(其他人構建它),但我可以嘗試按照要求獲取儘可能多的信息。但是它並沒有改變,因爲在棒棒糖出來之前,這個代碼一點都沒有改變。唯一改變的是,它不再適用於帶有棒棒糖的Sony Xperia Z。通讀日誌
更新1
我發現
W/ContextImpl( 858): Calling a method in the system process without a
qualified user: android.app.ContextImpl.sendBroadcast:1355
com.android.server.usb.UsbSettingsManager.blacklistedDeviceDetached:777
com.android.server.usb.UsbHostManager.usbDeviceRemoved:397
com.android.server.usb.UsbHostManager.monitorUsbHostBus:-2
com.android.server.usb.UsbHostManager.access$000:54
W/BroadcastQueue( 858): Permission Denial: receiving Intent
{act=android.hardware.usb.action.USB_DEVICE_DETACHED flg=0x10 (has extras) }
to ProcessRecord{3f67a3f 9138:com.edgetechlabs.drinkmate_play/u0a276}
(pid=9138, uid=10276)
requires com.sonyericsson.permission.BLACKLISTED_USB_DEVICE due to sender android (uid 1000)
,所以我說
<permission
android:name="com.sonyericsson.permission.BLACKLISTED_USB_DEVICE"
android:protectionLevel="signature" />
到我的清單,但我得到
W/PackageManager( 858): Package com.edgetechlabs.drinkmate_play
attempting to redeclare system permission
com.sonyericsson.permission.BLACKLISTED_USB_DEVICE; ignoring new declaration
所以有些東西隨着USB設備的許可而改變,但我不知道如何解決這個問題。我怎樣才能讓設備接受這個USB?
我明白你說的話,那將工作時,應用程序已經打開,但會在設備插入該工作打開應用程序?因爲這是所有其他手機上的功能。爲什麼只有這款手機才需要手動許可? – The4thIceman
我也在努力。我的應用程序也有同樣的要求。請查看我的更新以及其他一些發現。一旦找到任何解決方案,我會盡快回來。此外,您的貢獻將不勝感激。謝謝! – Deepti
在這一點上,我只是好奇,因爲我不再在這個項目上工作了。我滿足於這一點,只是責備索尼:)。我有一個預感,你可能正在研究我正在進行的項目。如果你確實在使用DrinkMate,那麼祝你好運,我希望你找到解決方案。但無論如何,你的答案基本上是正確的,並將被標記爲這樣 – The4thIceman