Run Code Online (Sandbox Code Playgroud)$ adb --help
...
Run Code Online (Sandbox Code Playgroud)-s SERIAL use device with given serial (overrides $ANDROID_SERIAL)
...
Run Code Online (Sandbox Code Playgroud)$ adb devices List of devices attached emulator-5554 device 7f1c864e device
...
Run Code Online (Sandbox Code Playgroud)$ adb shell -s 7f1c864e error: more than one device and emulator
?
为什么我的Android应用程序没有连接到服务器?
我在Android模拟器中运行应用程序,服务器端口9999和主机127.0.0.1在我的电脑,但只是没有连接,我认为这个方法不适合Android应用程序.
更新:我使用API 8 ... Android 2.2!
这是好工作!!谢谢大家 ;)
这是我的源代码:
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
//Java imports
//import android.util.Log;
import java.io.*;
import java.net.*;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
public class MainActivity extends Activity{
//Variaveis Interface
private Button ligar;
private Button enviar;
private EditText text1;
private TextView text2;
//Variaveis
static Socket cSocket;
static PrintWriter out;
static BufferedReader in;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle …Run Code Online (Sandbox Code Playgroud) 我正在访问服务器以进行Web服务调用.当我在与服务器相同的网络上进行开发时,我可以通过其内部IP地址访问Web服务,但不能访问其外部IP地址.但是,如果我不在网络上,我只能通过其外部IP地址访问它.尝试其中一个IP地址然后再回到另一个IP地址的最佳方法是什么?
这是我的代码示例,仅用于访问其中一个或另一个:
protected String retrieve() {
Log.v(TAG, "retrieving data from url: " + getURL());
HttpPost request = new HttpPost(getURL());
try {
StringEntity body = new StringEntity(getBody());
body.setContentType(APPLICATION_XML_CONTENT_TYPE);
request.setEntity(body);
HttpConnectionParams.setConnectionTimeout(client.getParams(), CONNECTION_TIMEOUT);
HttpConnectionParams.setSoTimeout(client.getParams(), SOCKET_TIMEOUT);
HttpResponse response = client.execute(request);
final int statusCode = response.getStatusLine().getStatusCode();
if (statusCode != HttpStatus.SC_OK) {
Log.e(TAG, "the URL " + getURL() + " returned the status code: " + statusCode + ".");
return null;
}
HttpEntity getResponseEntity = response.getEntity();
if (getResponseEntity != null) {
return EntityUtils.toString(getResponseEntity);
}
} catch …Run Code Online (Sandbox Code Playgroud) 我正在尝试编写自己的android http服务器.这很好,但我的AVD有问题.每次我想测试更改时,我都不想将我的应用程序下载到手机上.我想通过AVD连接到我的应用程序.要获取IP地址我正在使用此功能:
private String getLocalIpAddress() {
try {
for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {
NetworkInterface intf = en.nextElement();
for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) {
InetAddress inetAddress = enumIpAddr.nextElement();
if (!inetAddress.isLoopbackAddress()) { return inetAddress.getHostAddress().toString(); }
}
}
} catch (SocketException ex) {
Log.e("ServerActivity", ex.toString());
}
return null;
}
Run Code Online (Sandbox Code Playgroud)
在我的手机上一切正常,但当我在AVD上运行我的应用程序时,它显示ip:10.0.2.15,我无法连接到它.有没有办法连接我在AVD上运行的应用程序?如果它确实重要我的应用程序使用端口8080.
什么是android模拟器的IP地址,我在互联网上找到了SEVERAL信息,127.0.0.1,10.0.0.2或10.0.015从Web服务器(apache)调用模拟器.是模拟器的端口是固定的?
我有一个HTTP服务器在我的android模拟器上工作,听取端口8080.如何从同一台PC的浏览器连接到它?我试过127.0.0.1但无法连接.
我正在使用com.squareup.retrofit2:retrofit:2.2.0
HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
logging.setLevel(HttpLoggingInterceptor.Level.BODY);
OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
httpClient.addInterceptor(logging);
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("http://localhost:9000")
.addConverterFactory(GsonConverterFactory.create())
.client(httpClient.build())
.build();
final UserService service = retrofit.create(UserService.class);
Call<User> userCall = service.createUser(user)
Run Code Online (Sandbox Code Playgroud)
这是问题所在:当我运行execute它时,它会生成REST API请求但是当我使用enqueue它时什么都不做(没有例外,没有日志)
userCall.execute(); //this work
//this does not work
userCall.enqueue(new Callback<User>() {
@Override
public void onResponse(Call<User> call, Response<User> response) {
// no response
}
@Override
public void onFailure(Call<User> call, Throwable t) {
//nothing here
}
});
Run Code Online (Sandbox Code Playgroud) 我创建了一个 .NET Core Web api 端点,可以在其中检索一些想要在移动应用程序中显示的图像。我通过导航到该路线并通过邮递员在本地测试了端点,两者都工作正常(显示正确的响应)。但是,当我尝试从移动端访问端点时,它不起作用。我收到这个神秘的错误:
System.Net.Http.HttpRequestException: Network subsystem is down
Run Code Online (Sandbox Code Playgroud)
以下是更多异常信息:
System.Net.Http.HttpRequestException: Network subsystem is down ---> System.Net.Sockets.SocketException: Network subsystem is down
at System.Net.Http.ConnectHelper.ConnectAsync (System.String host, System.Int32 port, System.Threading.CancellationToken cancellationToken) [0x000c8] in /Users/builder/jenkins/workspace/archive-mono/2019-10/android/release/external/corefx/src/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/ConnectHelper.cs:65
Run Code Online (Sandbox Code Playgroud)
我不确定我在移动端做错了什么。我知道邮递员要显示它,我必须关闭 SSL 认证设置。我需要在移动端做类似的事情吗?
以下是我尝试调用端点的方法。我正在使用改装:
public static class FetchMediaService
{
public static INevarroApi apiService;
static string baseUrl = "https://localhost:5001";
public static async Task<List<Uri>> CallImagesEndpoint()
{
apiService = RestService.For<INevarroApi>(baseUrl);
var images = await apiService.GetImages();
return images;
}
}
Run Code Online (Sandbox Code Playgroud)
在哪里:
public interface INevarroApi
{
[Get("/images")]
Task<List<Uri>> GetImages();
}
Run Code Online (Sandbox Code Playgroud)
OnAppearing …