我正在使用以下webservice从Android发送推送通知.当我第一次调用此Web服务时,需要花费很多时间并且Android设备上不会发送推送通知.它只在从Android调用时才会发生.它完美地作为webservice.
[WebMethod]
public string SendGcm(String serviceKey,String registrationId ,string message) {
WebClient wc=new WebClient();
wc.Headers.Add("Authorization", "key=" + serviceKey);
NameValueCollection nameValues=new NameValueCollection
{
{"registration_id", registrationId},
{"collapse_key", Guid.NewGuid().ToString()},
{"data.payload", message}
};
var resp=wc.UploadValues("https://android.googleapis.com/gcm/send",
nameValues);
var respMessage = Encoding.Default.GetString(resp);
return respMessage;
}
Run Code Online (Sandbox Code Playgroud) java web-services android-ksoap2 google-cloud-messaging android-webservice
我需要创建一个与REST服务器对话的应用程序.
我发现答案:Android REST客户端,Sample? 但它是2012年.
是否有一个我可以遵循的教程(以及您建议的)以获得一个小的工作示例项目?提前致谢.
我使用a HttpURLConnection来检查服务器URL是否可用,使用以下代码:
try {
boolean connectionFailed = false;
URL knownURL = new URL("http://www.google.com");
httpConnection = (HttpURLConnection) knownURL.openConnection();
httpConnection.setConnectTimeout(5000);
responseCode = httpConnection.getResponseCode();
if (responseCode != 200) {
status = ConnectionStatus.NOT_CONNECTED;
}
}
catch(Exception e) {
connctionFailed = true;
}
Run Code Online (Sandbox Code Playgroud)
此代码在正常条件下正常工作.但是当没有Internet连接时(因为路由器断开连接或者没有热点),httpConnection.getResponseCode()没有执行(函数不返回).我怎样才能解决这个问题?
android web-services httpurlconnection ws-client android-webservice
再会,
我有这个屏幕,我想在其中显示投标的赢家和输家。
它需要看起来像这样:
TextView - Winners
Name and bid amount
Name and bid amount
Name and bid amount
--------------------
Textview - Losers
Name and bid amount
Name and bid amount
Name and bid amount
Name and bid amount
Run Code Online (Sandbox Code Playgroud)
来自网络服务的响应如下:
{
"winningBids": [
{
"amount": 500,
"quantity": 1,
"name": "Craig",
"status": "WINNING"
}
],
"losingBids": [
{
"amount": 461,
"quantity": 1,
"name": "Bob",
"status": "LOSE"
},
{
"amount": 460,
"quantity": 1,
"name": "James",
"status": "LOSE"
}
]
}
Run Code Online (Sandbox Code Playgroud)
我想过在同一个屏幕上有 2 个 …
我使用运行的python flask框架在本地编写了一个Web服务localhost:5000,我通过编写从我的计算机浏览器成功运行此Web服务http://localhost:5000/toi/something
现在我试图通过连接机器从我的Android设备的浏览器调用相同的服务.我这是第一次这样做,所以我不确定它是否有效,或者我做错了什么,但它没有显示我的Android设备上的输出.完成后,我将在我的Android应用程序中以编程方式调用Web服务.
谢谢

我希望利用我的NodeJS + SocketIO服务器应用程序和新的基于Android的客户端应用程序.目前我在Android中使用okhttp3 for Websockets.但我想在socket.io中使用WebSockets.
有没有其他人使用WebSocket对SocketIO进行此类工作.所以请帮助我.
我正在尝试使用org.java_websocket.client.WebSocketClient API在android中连接安全websocket连接wss://,但无法与https连接.但是它与ws://一起工作正常.这是我的代码.
private void connect(String websocketEndPointUrl) throws Exception {
URI uri;
try {
websocketEndPointUrl="wss://echo.websocket.org:443";
Log.i(TAG, " WSURL: " + websocketEndPointUrl);
uri = new URI(websocketEndPointUrl);
} catch (URISyntaxException e) {
Log.e(TAG, e.getMessage());
return;
}
mWebSocketClient = new WebSocketClient(uri,new Draft_17()) {
@Override
public void onOpen(ServerHandshake serverHandshake) {
Log.i("Websocket", "Opened");
}
@Override
public void onMessage(String s) {
//final String message =s;
}
@Override
public void onClose(int i, String s, boolean b) {
Log.i("Websocket", "Closed " + s);
}
@Override
public void onError(Exception e) …Run Code Online (Sandbox Code Playgroud) 1.without proguard 一切正常。在启用 Proguard 时,所有头部和身体模型都变得模糊不清。
2.Retrofit2 无法通过模型对象传递数据。
D/OkHttp: Content-Type: application/json
Content-Length: 80
{"a":{"a":"123","b":"***","c":"","d":"Data","f":"1.0"},"b":{"a":""}}
--> END POST (80-byte body)
Run Code Online (Sandbox Code Playgroud)
下面提到的 Proguard 规则已经添加到我的代码中,但仍然遇到同样的问题,请帮助我解决这个问题。
# Retrofit
-dontwarn retrofit2.**
-dontwarn org.codehaus.mojo.**
-keep class retrofit2.** { *; }
-keepattributes Signature
-keepattributes Exceptions
-keepattributes *Annotation*
-keepattributes RuntimeVisibleAnnotations
-keepattributes RuntimeInvisibleAnnotations
-keepattributes RuntimeVisibleParameterAnnotations
-keepattributes RuntimeInvisibleParameterAnnotations
-keepattributes EnclosingMethod
-keepclasseswithmembers class * {
@retrofit2.* <methods>;
}
-keepclasseswithmembers interface * {
@retrofit2.* <methods>;
}
# Platform calls Class.forName on types which do not exist on Android to determine platform.
-dontnote retrofit2.Platform …Run Code Online (Sandbox Code Playgroud) 我想使用volley库在android中获取JSONObject的值.
这是我的MainActvity.java代码.
String url = "http://someexample.com/signin.php";
StringRequest postRequest = new StringRequest(Request.Method.POST, url,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
JSONObject jsonResponse = new JSONObject(response).getJSONObject("type");
String myObjAsString = jsonResponse.toString();
mTV.setText(myObjAsString.toString());
} catch (JSONException e) {
e.printStackTrace();
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
error.printStackTrace();
}
}
) {
@Override
protected Map<String, String> getParams() {
Map<String, String> params = new HashMap<>();
// the POST parameters:
params.put("email", "example@outlook.com");
params.put("password", "********");
return params;
}
}; …Run Code Online (Sandbox Code Playgroud) 我已经使用了以下代码,但它在执行Asyntask时出错,而且我已经发布了我的JsonParser类.请指导我如何删除此错误.
public class Login extends Activity implements OnClickListener {
private EditText user, pass;
private Button mSubmit, mRegister;
private ProgressDialog pDialog;
// JSON parser class
JSONParser jsonParser = new JSONParser();
private static final String LOGIN_URL = "http://******/web_service/index.php";
//www.itsoft-solutions.net
//JSON element ids from repsonse of php script:
private static final String TAG_SUCCESS = "success";
private static final String TAG_MESSAGE = "message";
public static String uname;
public static String password;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.login); …Run Code Online (Sandbox Code Playgroud)