简体   繁体   English

无法在Android中连接到localhost

[英]Can't connect to localhost in Android

I have an android project which I made in my desktop .I connect to the internet over wifi .But when I run the same project in laptop I cant connect to internet over my mobile data operator. 我有一个在桌面上制作的android项目。我通过wifi连接到Internet。但是当我在笔记本电脑上运行同一项目时,我无法通过移动数据运营商连接到Internet。 Where's the problem? 哪里出问题了?

I found "No internet connection" as volleyError 我发现“没有互联网连接”为volleyError

The way I do this is by using port forwarding: 我这样做的方法是使用端口转发:

  1. Connect your device and open chrome on both your mobile and laptop browser. 连接设备并在移动设备和笔记本电脑浏览器上打开Chrome。
  2. On the URL tab, type chrome://inspect 在网址标签上,输入chrome:// inspect
  3. Click on port forwarding and add a new row, with port as 8888 and IP as localhost:8080. 单击端口转发并添加新行,端口为8888,IP为localhost:8080。 在此处输入图片说明
  4. Now in your android application code, replace localhost:8080 with localhost:8888. 现在在您的android应用程序代码中,将localhost:8080替换为localhost:8888。

Basically now on 8888 your mobile will the connect to the computers localhost. 现在基本上在8888上,您的手机将连接到计算机localhost。 Note: Make sure that chrome is open on both your laptop and the device. 注意:确保Chrome在笔记本电脑和设备上均打开。 And when you type chrome://inspect you should be able to see the device you have attached. 而且,当您输入chrome:// inspect时,您应该能够看到已连接的设备。

Refer to this for more help: https://developer.chrome.com/devtools/docs/remote-debugging 请参阅此以获得更多帮助: https : //developer.chrome.com/devtools/docs/remote-debugging

Also add <uses-permission android:name="android.permission.INTERNET"/> to your Androidmanifest.xml 还要将<uses-permission android:name="android.permission.INTERNET"/>到您的Androidmanifest.xml中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM