Is there a way to test android app by using local (ie computer on which emulator is running) JSON file instead of giving it URL of online file. In my university we have proxy login which means that android apps cant access the internet so i need to use a file on my system for testing app on emulator. do i need to setup a server like wamp or can i directly pass filepath as argument to JsonArrayRequest?
I dont have a clue about other workarounds, but you can set up Wamp Server or Xamp Server and call the url from emulator,
And yes in order to access the localhost inside Emulator you can use following IP:
10.0.2.2 for Default emulator and 10.0.3.2 for GenyMotion
and yes to mention i got the GenyMotion reference from this answer link to answer
Related
I have a Xamarin app and localhost API. I'm trying to connect to the API from the app, but it could not be found. I edited my applicationhost.config file and I tried localhost, 10.0.2.2 and my IP address in the call, but it was not working.
So, how do I configure simple API access? (The API itself is working well)
There is simple workaround to connect Emulator & Simulator to localhost API.
Download third party software NgRok for Windows at any specific location of your PC. It just contains one executable file called ngrok.exe (you not need to install it).
Now execute your service on your preferred browser. Than follow below steps.
Open your ngrok.exe file path in command prompt
Keep your service url (take from your browser) with prefix ngrok http --host-header=rewrite and hit enter.
Now go to your browser where you have executed your service open new tab and type localhost:4040 than press enter -->Go to status there you will find your public url which you can use in your mobile application.
Note: Url structure should be like this public const string BaseUri = "https://8c56892f.ngrok.io/"; followed by / in last. Try not to append unnecessary /.
Benifits
You can debug services from one Visual Studio to another.
Your url will be active until you close command prompt.
In browser or command prompt track your requests status like Ok, Not found etc.
For more information visit this https://www.c-sharpcorner.com/article/exposing-local-web-server-to-internet-using-ngrok/
Hope it help you.
That 10.0.2.2 address is used for the Google emulators. For the Microsoft emulator you want to use 169.254.80.80. If that doesn't work then it must mean you have the firewall on and it's blocking the traffic. That can be solved by adding a new incoming rule for the program or port.
I have a little problem with the Network Image from Flutter.
When I try to load an Image from the internet it is working fine but as soon as I try to load from my Localhost it's showing nothing, no exception in the logcat, just nothing.
I have also looked to related questions but nothing from the mentioned solutions worked.
Here is an example URL http://IP_ADDRESS/path/to/image.jpg
I have already included the internet permission in Android manifest.
I am testing on a real Android device.
When I'm pasting the URL in my browser it shows the right image.
i set the base url on flutter app as my local computer ip first
then when i get url image from server i change the "localhost" part into computer ip address and it showen in the app and external device also
the url link for image must be seen by your device , in your case localhost means your phone device but not your computer . if your device is web (chrome) you will not see the localhost , but if your device is android phone (usb or virtual) then you have to use your computer ip instead of using localhost like :
http://192.168.1.10/myproject/images/myimage.png
because the localhost in this case is the webserver installed on your device .
if you want to use localhost like :
http://localhost/myproject/images/myimage.png
then you have to install a webserver on your mobile device.
I'm having trouble accessing my server (WAMP) using my real android device. I have an app that downloads the data and parsing it to my listview. In the emulator everything is working fine using "10.0.2.2" I tried 10.0.2.2:80, 10.0.2.2(without port #), (my laptop's ip) 192.168.254.103:80 and 192.168.254.103 (without port #) in my url. My WAMP is online and I even tried turning off firewall. Is there something missing?
UPDATE
I tried browsing via my phone's browser the ip address of my laptop and it says "FORBIDDEN". i tried configuring the httpd.conf of apache based on what I've researched but still can't access the server. please help.
Turn off Firewall -
Give permission to "WAMP folder" by using Folder
sharing options - Basically access to "All" for read, write
I am getting google.com inside my WebView, but am not getting my localhost in that.
Can anybody help me?
Use 10.0.2.2 instead. This is a special ip address that the emulator routs to local host on your dev machine. assuming that emulator and the webserver are running on the same machine.
Make sure you are loading WebView with full Urls.
http://www.google.com
http://10.0.2.2/
and not:
www.google.com
google.com
All of these will work while using Browser, but you must supply a full valid url for WebView. Banged my head against the keyboard for an hour figuring that out.
If you're having connectivity issues in the emulator, try overriding the dns in the build path.
Window > Preferences > Android > Launch
Default emulator options: -dns-server 8.8.8.8
I have created a website and published it in my local computer using IIS, I tried to access this site in the android emulator using WebView:
http://localhost:83
with the same results as the OP.
I changed to:
http://10.0.2.2:83
and worked.
Try your actual ip [with the port number if required] instead of localhost.
Just type localhost name and port like this: http://127.0.0.1:80
If you're using a physical device to run, then,
make sure your website is running at 192.168.x.xxx:port
set the full url in your activity, such as,
mwebView.loadUrl("http://192.168.1.107:8000/");
add
android:usesCleartextTraffic="true"
in AndroidManifest.xml to fix 'cleartext not permitted' error caused for not using https
If in emulator, then,
host website in localhost (127.0.0.1:port)
for url
mwebView.loadUrl("http://127.0.0.1:3000");
previous 3rd step
(Make sure to remove the manifest permission before release. Or it would be a security concern for your app.)
I added the IP Address of the local server and it is working fine.
You can find you ip address by going to
COMMAND PROMPT
type> ipconfig
Now, add the ipv4 IP Address shown in your Webview URL. It will work fine.
I've started android emulator app and trying to open from embeded browser locally started web-site, but local dns name (from /etc/hosts) is not resolved. Is there any option to enable local resolving?
Refer this URL. The issue is 127.0.0.1 is not the correct IP for accessing local server sites on emulator.
http://localhost:8080/MyTestPage.html // URL to use in computer browser
http://10.0.2.2:8080/MyTestPage.html // URL to use in emulator browser
However, you need to do some configuration changes as suggested in the URL.
Here's how to access a locally hosted website in the Android emulator.
Use IIS/Apache to host the application.
For some obscure reason, Android Virtual Device would not let you connect to the development server created by Visual Studio.
Once you host the application, use your IP address as the web address to connect to the local website. "localhost" just won't work with the AVD. Just go to the command prompt and type ipconfig to get your local ip address. You should be looking for IPv4 Address
Here's Android AVD connecting to Apache (XAMPP)
Here's connecting to IIS
Good Luck everyone and happy testing!!
You should specify your local ip address in browser, something like 192.168.xx.xx