我有一個桌面Java應用程序,也是一個Android應用程序。兩個應用程序一起工作通過USB桌面java應用程序複製和傳輸android數據
桌面應用程序中的用戶有一個按鈕來啓動設備數據應用程序到計算機應用程序之間的傳輸,反之亦然。
因此,我需要用簡單的USB電纜傳輸數據,並且沒有互聯網連接/ WiFi /藍牙/ adb。
我發現了兩個Java MTP庫在Windows上運行,以解決我的問題,而Android的USB Host/accesory fonctionnality:
jMTP成功地識別出我的Android設備,文件夾,和其他的東西
我有成功轉讓在計算機中的文件--->設備,但我有一個錯誤,當我嘗試在設備--->計算機
我把我的代碼EXP後傳輸文件laination。
jusbpmp但我沒有可能轉移設備--->計算機。
USB主機/ accesory不是有用,因爲轉移是從桌面應用程序啓動,而當我在Android developper指南網站上閱讀,它似乎沒有從我所需要的,或者對應也許,如果用戶開始轉移從設備。
我嘗試從1周成功完成這項任務,但似乎我需要幫助。
的Java + jMTP代碼
private static void jMTPeMethode()
{
PortableDeviceManager manager = new PortableDeviceManager();
PortableDevice device = manager.getDevices()[0];
// Connect to USB tablet
device.open();
System.out.println(device.getModel());
System.out.println("---------------");
// Iterate over deviceObjects
for (PortableDeviceObject object : device.getRootObjects())
{
// If the object is a storage object
if (object instanceof PortableDeviceStorageObject)
{
PortableDeviceStorageObject storage = (PortableDeviceStorageObject) object;
for (PortableDeviceObject o2 : storage.getChildObjects())
{
if(o2.getOriginalFileName().equalsIgnoreCase("Test"))
{
//Device to computer not working
PortableDeviceToHostImpl32 copy = new PortableDeviceToHostImpl32();
try
{
copy.copyFromPortableDeviceToHost(o2.getID(), "C:\\TransferTest", device);
} catch (COMException ex)
{
}
// //Host to Device working
// BigInteger bigInteger1 = new BigInteger("123456789");
// File file = new File("c:/GettingJMTP.pdf");
// try {
// storage.addAudioObject(file, "jj", "jj", bigInteger1);
// } catch (Exception e) {
// //System.out.println("Exception e = " + e);
// }
}
System.out.println(o2.getOriginalFileName());
}
}
}
manager.getDevices()[0].close();
}
這是代碼和錯誤
`
Nexus 9
---------------
Music
Podcasts
Ringtones
Alarms
Notifications
Pictures
Movies
Download
DCIM
Android
! Failed to get IStream (representing object data on the device) from IPortableDeviceResources, hr = 0x80070057
test
ReleveData
`
我在網上讀80070057的結果是一個通用的窗口例外。
編輯:
Windows site say爲HR錯誤 ERROR_INVALID_PARAMETER 80070057: 由應用程序提供的參數是無效的。
但我沒有看到女巫參數無效
這裏是C類的庫使用了傳輸數據的設備計算機的link,你可以看到我的錯誤行230
這是我使用的jMTP庫。
你能幫助我,還是以另一種方式去做我需要的東西(Usb4Java,libUSB)?我會很感激。
提前致謝。