My API is 23. I am having issues where my device does not send the
connection request. I have tried on the emulator, a phone running 6.0, and
a tablet with 5.1.
Can someone please give me some assistance? Been banging my head against
the wall for hours now.
import android.app.Activity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.os.Bundle;
import android.widget.TextView;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
public class MainActivity extends Activity {
/**
* Called when the activity is first created.
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final Button ConnectButton = (Button) findViewById(R.id.ConnectButton);
final TextView IpAddressEntry = (TextView)
findViewById(R.id.IpAddressEntry);
final TextView PortEntry = (TextView) findViewById(R.id.PortEntry);
String IpAddress = IpAddressEntry.getText().toString();
String Port = PortEntry.getText().toString();
ConnectButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
HttpURLConnection connection = null;
String IpAddress = IpAddressEntry.getText().toString();
String Port = PortEntry.getText().toString();
try {
String urlConnect = "http://" + IpAddress + ":" + Port +
"/connect";
URL url = new URL(urlConnect);
connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.connect();
Log.i(urlConnect, "myIP");
connection.setDoOutput(true);
InputStream is = connection.getInputStream();
BufferedReader reader =new BufferedReader(new
InputStreamReader(is, "UTF-8"));
String webPage = "",data="";
while ((data = reader.readLine()) != null){
webPage += data + "\n";
}
} catch (Exception e) {
} finally {
if (connection != null) {
connection.disconnect();
}
}
}
});
}
}
--
You received this message because you are subscribed to the Google Groups
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/android-developers.
To view this discussion on the web visit
https://groups.google.com/d/msgid/android-developers/b5cac5a6-575c-43ab-8edf-9d58834aa51b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.