My Android app uses curl to make network calls. I want to find out how I can get the URL that's present in the WiFi proxy auto config in an android device, inside of my application to actually be able to route the charles call through the proxy URL retrieved from the PAC file ?
This question is old, but this might be interesting for anyone else coming from search engines:
Do you know which URL the PAC resides on? If not, I would try to connect to the same WiFi with a PC and do a wireshark trace. When you initiate the connection to the WiFi, an option 252 is sent with the DHCP-lease, specifying where to download the PAC-file from. For example, your client might be told to download http://pac.yoursite.com/pac_file.txt - - - or simething like that.
Then, you can open a browser and navigate to that url, which will download the PAC-file for you to read as JavaScript.
Related
I am new to Django. I have created an API named http://127.0.0.1:8000/api/update/1/ and it works perfectly in the browser and on the Postman app.
However, when I am trying to access the API from the Android app it is returning NULL.
The android code works when the API is the following.
http://newsapi.org/v1/articles?source=bbc-news&sortBy=top&apiKey=8190df9eb51445228e397e4185311a66
However, it does not work when the API is the following, even if the following API works just fine from my browser running in the same PC and from the Postman application.
http://127.0.0.1:8000/api/update/1/
I am attaching the code where API call is made.
protected String doInBackground(String... args) {
String xml = "";
String api = "http://127.0.0.1:8000/api/update/1/"; // returns NULL works in Postman app and in the browser
// String api = "http://newsapi.org/v1/articles?source=bbc-news&sortBy=top&apiKey=8190df9eb51445228e397e4185311a66"; // works in all places
String urlParameters = "";
xml = Function.excuteGet(api, urlParameters);
return xml;
}
Can anyone help me with this? Thanks in advance.
If you are testing your application from a real android device then you need to put the IP address of your PC while you are trying to connect to your Django server through APIs. And yes, you need to be in the same network as well. So you need to check the following things.
Make sure that the PC (where you are running the server) and the Android device (where you are testing your application) are in the same network (connected with same Wifi network maybe).
Make sure you are connecting to the IP address of your PC where the server is running. For example, right now, the IP address of your PC is 192.168.0.100. Then, you need to connect to this IP address and call your API like the following.
http://192.168.0.100:8000/api/update/1/
Make sure you are accepting requests to the port 8000 in your PC. Check your Firewall configuration if it is blocking any incoming requests to the 8000 port. If it is found blocking, then please allow an incoming request to the 8000 port using the following.
sudo ufw allow 8000/tcp
If there is nothing which is helping you, then please check your Android code to check if the API calling is okay. I would strongly recommend using Volley for API calls suggested in developers documentation.
Last, but not the least, please check if you have necessary permission in your AndroidManifest.xml file. You need to add the following permission to grant your application to use the internet.
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
To be able to connect your localhost (I assume you are using emulator, I can edit the answer if not)
You need to use the following url:
http://10.0.2.2:8000/
Please run your django development server using the following command.
python manage.py runserver 0.0.0.0:8000
Once you get it running, in a new terminal window find out the ip address of your computer in your wifi/network subnet using the following command
Ipconfig or ifconfig (depends on your OS)
Then change the base url of your api from 127.0.0.1 to the ip you found in the above step. Now connect the android phone in which your app is being tested to your same wifi or network to which the computer running django is connected.
Now you can request and receive response.
127.0.0.1 is the home of your system, your android app will not be able to access that. You need to do it like this.
1)Andoird manifest to put internet permission and network acceess
2) if using Android simulator on local machine. Use 10.0.2.2. alias created by default for 127.0.0.1 i.e losthoast.
Its works for me
The API isn't working in POSTMAN I tried http://127.0.0.1:8000/api/update/1/ shows an error because it requires some params to be inputted.
in this case, http://newsapi.org/v1/articles?source=bbc-news&sortBy=top&apiKey=8190df9eb51445228e397e4185311a66 the required params have been provided to the API, ie source, sortBy & apiKey
It is possible to call local api with some minor changes.These were the steps I did to hit the local django api from my android app.
You need to be connected to same network. Better create a hotspot from your pc or laptop and connect android with it
Create static IP from your system. If you are on VM you may require additional network adapter. Please google it as there are plenty of videos and blogs on the same.
Host django on the created local IP.
You are then good to go with your android app.
You can not access a local api outside from that local device. 127.0.0.1 is the local address of its own. If you want to access the api outside from local device, replace the ip with the ip that is open to outside. For example, 192.168.43.2 is a ip that is accessible from outside. Update your api with the accessible ip(use ifconfig or ipconfig in terminal to obtain the ip and use that ip to access from outsid?). Also, please make sure if you have proper permission in AndroidManifest.xml file.
For me, the problem was that my server was running on HTTP, not HTTPS. Once I set up my SSL certificate, everything worked fine. I'm using Expo and strangely the API works when in development mode through the Expo app, but after I build an APK it fails to connect to any non-HTTPS server.
In local host You must start the server and also do app development in same system then only it works for you..
There is no way of calling local APIs from android. Leave it.
Application use: I am creating a connection between a tablet and a desktop. This tablet will send command to my desktop that my java app will then interpret and do accordingly. One of these features I would like to include is controlling Skype. Such as focusing on it. Switching chats. Initiating call. Sending message. ect. But I can't seem get the URI api to work. (This is the only known api that will allow me to initiate calls and chats, so if you know of any other. Please do tell.)
I am not sure If I am doing it right being that this is my first time using a URI ever. This is what I have using
import java.net.URI
public void uriTest(){
try{
URI uri = URI.create("skype:echo123?call");
}catch(Exception ex){
ex.printStackTrace();
}
}
What am I missing? I know it is probably a lot. Is there some sort of way to implement it. Or when you call .create() does it automatically do it for you?
Any help or clarification will be greatly appreciated.
Your code constucted an URI and now you have one, nothing more, nothing less. An URI is - as the name "Universsal Resource Identifier" says - just an identifier.
What you probably want to do is establish a connection to a location identified by that URI. So you need a special identifier, a so-called "Universal Resource Locator" or URL:
URL url = new URL("skype:echo123?call");
Still nothing happening since we only defined a location. Next you have to connect to it:
URLConnection conn = url.openConnection();
Now you got an URLConnection-object (in this case a HttpURLConnection) and you can operate with it: post data, read responses etc. Read up on the API of java.net.HttpURLConnection to learn more.
You should write a web application, and deploy it on a web server program such as Tomcat, on your desktop machine. You can then write an app on your tablet which would connect to the server and send commands to the server.
The web application could parse the commands and do something with Skype application running on the desktop.
You would probably write a JSON api and deploy it on the Tomcat server, and then invoke the JSON api from the tablet app.
completely newby in Android, coming from c# world..
I've written a little private app for android and that must not be available on play store and the like...
the app is using JTDS to directly connect to local SQL Server to manage "inputs" from the device, and it works as expected :)
again, the app can not be updated via play store, but now I'd like to provide a feature to update it [occasionally it will :)]
so I'd like to verify on a local network share a text file containing the latest build available and, eventually, copying the "new" apk to android \Download directory...
but I still have to find a way to "read\connect" the the LAN's share...
I've seen other threads like
How to use httpget in my app
and basically my code follows How to get file via HttpGet from pc in local network on android
but the code "fails" with 404 status code...
in the HttpGet(file) I've provided the LAN location of the file I need to read, like
String file = "http://192.168.x.xxx/NetworkShare/file2read.txt";
the share is on a Windows7 machine with readonly permissions and no authentication required... It's not a Windows Domain, it's just a WorkGroup so permissions troubles should be excluded...
I'm still checking with the emulator and not the physical devices...
the manifest already includes Internet permissions, WIFI_STATE, NETWORK_STATE
If helps, I'm using Android Studio 1.1.0
any hint or alternative?
TIA
asql
What you try to do with HttpGet won't work with a Lan location because when you share a directory you are using SMB,CIFS or NFS protocol and it's impossible to access those files via HTTP. If you want to use HttpGet you must publish your files through a HTTP server.
I think there is no way to mount a drive programmatically in Android. It is possible with busybox but maybe you need to be root.
The best way to do what you want is getting the information from a webservice or maybe downloading your file from a ftp server.
I have an Android Application that has to fetch an XML file from a particular URL.
To do this, I first check if an internet connection is available and if so, I download the file. This works fine.
The issue happens when I use my app in a network where users can connect to the internet but need to provide a username and password before they can access any page i.e. Limited Access.
How can I test for Limited Access to the network?
Thanks.
To determine that the user has a fully functioning network connection try to open a web link programmatically in background if you get a success status then internet connection is available else user has limited access.This may help you.Have a look
I have an android application that plays music from a site, however to authenticate to the stream, you need to send a cookie first I.E:
http://example.com/site/content?id=SOMEID = mp3 formatted stream
If you access the url without a cookie, you'll get a Server 500 error.
If you have a cookie, then you'll get the stream.
For the life of me, I can't figure out how to make the mediaplayer play a URL while sending a cookie.
I can play any url that doesn't require a cookie, however.
As far as I can tell you can't. Almost everything MediaPlayer does is done in native code, including opening any connections, so there is no way to access the stream it is using AFAICT.
One possible workaround is to create a web server in your Android app, have it authenticate and download your MP3 and having your MediaPlayer call setDataSource with your local server's address (something like http://127.0.0.1:8000/mymp3.mp3). You can have the playback occur while your web server class is still downloading so ideally your users would notice a difference.