問題描述
我為 Android 應用程序實現了一個 Web 服務.Web 服務在我的本地主機 (192.168.1.2) 上運行.使用 Android 模擬器,我成功連接到 Web 服務.我嘗試使用調試模式將我的 Android 設備連接到 Web 服務,但沒有成功.所以我的問題是,是否可以在不使用真實 IP 的情況下將 Android 設備連接到在我的本地主機(192.168.1.2)上運行的這個 Web 服務?
I implemented a web service for an Android application. The web service is running on my local host (192.168.1.2). Using the Android emulator I succeeded to connect to web service. The I tried to connect my Android device using debugging mode to web service but it didn't work. So my question is if it is possible to connect an Android device to this web service that is running on my local host (192.168.1.2) without using a real IP ?
推薦答案
google支持的更簡單的方法!
- 將手機通過usb連接到電腦并開啟usb調試
- 在您的計算機上打開 Chrome 瀏覽器并準確輸入以下地址:
chrome://inspect/#devices
- 現在您可以通過端口轉發按鈕將您的計算機端口鏈接到您的設備端口.在我的計算機上,我在地址
localhost:61437
上有服務,我只是將它鏈接到設備的 8081 端口.記得勾選啟用端口轉發"復選框 - Connect your phone via usb to computer and enable usb debugging
- On your computer open Chrome browser and type exactly this address:
chrome://inspect/#devices
- Now you can link your computer port to your device port by port forwarding button. On my computer I have service on address
localhost:61437
and I just linked it to device's 8081 port. Remeber to check 'Enable port forwarding' checkbox 我電腦上的服務屏幕 (
localhost:61437
)
It's much simpler way supported by google!
使用相同服務 (localhost:8081
) 的移動瀏覽器屏幕.就是這樣.您也在您的應用程序中使用此服務地址
screen from my mobile browser with the same service ( localhost:8081
). And that's it. Also you use this service address in your application
這篇關于將 Android 設備連接到本地主機上的 Web 服務的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!