我在我的Android应用程序中使用谷歌地图,并在我的应用程序中成功加载地图.我使用以下代码在我的应用中初始化谷歌地图:
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(Places.GEO_DATA_API)
.addApi(Places.PLACE_DETECTION_API)
.addApi(LocationServices.API)
.enableAutoManage(this, this)
.build();
Run Code Online (Sandbox Code Playgroud)
谷歌地方api很适合我,但今天使用地方自动完成时发生错误!这是第一次发生此错误:
Status{statusCode=PLACES_API_INVALID_APP, resolution=null}
Run Code Online (Sandbox Code Playgroud)
我使用正确的api密钥,我的所有代码都是正确的,因为它一直工作到今天.但突然发生了这个错误.请帮帮我:)提前谢谢
我从服务器收到(步骤 1)一个soapString,我想将此字符串转发(步骤2)到另一台服务器。
public interface StepTwoRestAdapter {
@Headers({"Content-Type:text/xml"})
@POST("/services/step2/forwardSoap")
Observable<String> order(@Body SoapString soapString);
}
Run Code Online (Sandbox Code Playgroud)
在上面的这种情况下,“/webservices/step2/forwardSoap”的 afgter my.server.com 始终保持不变。我怎样才能使这部分变量?
这里的技巧是,在第一个响应的响应中指定了第二个服务器(用于第 2 步)。
编辑:现在,我使用@Tabish Hussain 的提议
public interface StepTwoRestAdapter {
@Headers({"Content-Type:text/xml"})
@POST("/{urlPath}")
Observable<String> order(@Body SoapString soapString, @Path("urlPath") String urlPath);
Run Code Online (Sandbox Code Playgroud)
}
然后我打电话
restAdapter.create(StepTwoRestAdapter.class).order(new TypedString(soapString), uriPath)
Run Code Online (Sandbox Code Playgroud)
而我的 uriPath 是“services/step2/forwardSoap”
但是改造然后调用:https : //my.server.com/services%2Fstep2%2FforwardSoap
如您所见,“/”被“%2F”替换
当使用proguard改装时,我得到以下异常(注意,没有Proguard一切正常):
java.lang.ClassCastException: com.google.gson.internal.LinkedTreeMap cannot be cast to com.path.to.my.model
at com.path.to.my.callback.onResponse(Unknown Source)
at retrofit.ExecutorCallAdapterFactory$ExecutorCallback$1.run(Unknown Source)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5351)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:908)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:703)
Run Code Online (Sandbox Code Playgroud)
我的proguard文件如下:
-dontwarn okio.**
-dontwarn retrofit.**
-keep class retrofit.** { *; }
-keepattributes Signature
-keepattributes Exceptions
Run Code Online (Sandbox Code Playgroud)
与我正在使用的Retrofit相关的依赖项是:
compile 'com.squareup.retrofit:retrofit:2.0.0-beta1'
compile 'com.squareup.retrofit:converter-gson:2.0.0-beta1'
Run Code Online (Sandbox Code Playgroud)
为什么会这样?我怎样才能找到问题?故障排除方法非常有帮助.提前致谢!
我试图将图像发布到服务器.这是我在脚本服务器提供给我的服务器端的php变量名:
$value1 = $_POST["value1"]; // string value
$value2 = $_POST["value2"]; // string value
$img_1 = $_FILES["fileToUpload1"]["name"]; // image file
$img_2 = $_FILES["fileToUpload2"]["name"]; // image file
Run Code Online (Sandbox Code Playgroud)
这是我发布值的代码 -
RequestBody fileBody = RequestBody.create(MediaType.parse("image/png"), path.toString());
RequestBody fileBody1 = RequestBody.create(MediaType.parse("image/png"), path.toString());
Call<uploadResponseModel> call = adapter.uploadValues("test1","test2",fileBody1,fileBody);
call.enqueue(new Callback<uploadResponseModel>() {
@Override
public void onResponse(Response<uploadResponseModel> response, Retrofit retrofit) {
Log.i("TAG", "retro onResponse :" + response.body().getResponse().getStatus());
}
@Override
public void onFailure(Throwable t) {
Log.i("TAG", "retro onFailure :" + t.getCause());
}
});
Run Code Online (Sandbox Code Playgroud)
适配器类:
public interface RetrofitAdapter {
@Multipart
@POST("/TestApp/img_upload.php") …Run Code Online (Sandbox Code Playgroud) 使用代码流失时会造成不便
abstract class View {
abstract fun findViewById(id: Int): View
abstract fun setOnClickListener(listener: (View) -> Boolean)
}
class ViewHolder(itemView: View) {
init {
child1.setOnClickListener { false }
}
val child1 = itemView.findViewById(1)
val child2 = itemView.findViewById(2)
}
Run Code Online (Sandbox Code Playgroud)
编译器抱怨说:
Kotlin: Variable 'child1' must be initialized
Run Code Online (Sandbox Code Playgroud)
所以我必须添加一个额外的功能,并在每次构建后调用它:
class ViewHolder(itemView: View) {
val child1 = itemView.findViewById(1)
val child2 = itemView.findViewById(2)
fun bindEventHandlers() {
child1.setOnClickListener { false }
}
}
val vh = ViewHolder(v)
vh.bindEventHandlers()
Run Code Online (Sandbox Code Playgroud)
那么,有没有方便的方法来做这样的init?使用Android RecyclerView和ListView时经常会发生这种情况.
我正在努力获得最高的定位精度,我从GPS供应商那里学到了这一点.我只需要获得一次位置,所以我不关心对电池寿命的影响.在我的功能代码中,位置似乎在完全不准确(1 + km)到非常准确(10m内)之间交替.在我的应用程序的测试中,我在手机上启用/禁用位置,打开/关闭wifi,打开/关闭数据.这只是为了试验,看看每个如何影响一般的准确性和应用程序.
以下代码是来自位置活动的onCreate方法:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.map_layout);
mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map_fragment))
.getMap();
mMap.setMyLocationEnabled(true);
locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
Criteria criteria = new Criteria();
//criteria.setAccuracy(Criteria.ACCURACY_HIGH);
provider = locationManager.getBestProvider(criteria, true);
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.build();
// Create the LocationRequest object
mLocationRequest = LocationRequest.create()
.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)
.setInterval(2 * 1000) // 10 seconds, in milliseconds
.setFastestInterval(1 * 1000); // 1 second, in milliseconds
}
Run Code Online (Sandbox Code Playgroud)
但是,当我添加该criteria.setAccuracy(Criteria.ACCURACY_HIGH);行时,我的应用程序崩溃了.
到底是怎么回事?
编辑:这是logcat错误:
E/AndroidRuntime: FATAL EXCEPTION: main
E/AndroidRuntime: Process: com.locationget, PID: 16663 …Run Code Online (Sandbox Code Playgroud) 我正在使用GSON库来序列化和反序列化客户端和服务器端的Java对象.我有一个场景,我在客户端上有一个以毫秒为单位的日期,但在服务器上,我有相同的数据类型的字段Date.以下是客户端的示例代码 -
class Dog {
long id;
long purchaseDate; //This is in milliseconds
String name;
boolean status;
}
Run Code Online (Sandbox Code Playgroud)
在服务器端 -
class Dog {
long id;
Date purchaseDate; //Convert milliseconds to date
String name;
int status; //If boolean is false then 0 else 1
}
Run Code Online (Sandbox Code Playgroud)
如何使用GSON库来完成它.如果通过GSON无法实现,那么哪个库适合这种序列化/反序列化?
我从服务器获得空 json (“{}”) 作为删除响应,代码为 204。
在okhttp3.internal.http.HttpEngine课堂上,有一个令人讨厌的事情被抛出:
if ((code == 204 || code == 205) && response.body().contentLength() > 0) {
throw new ProtocolException(
"HTTP " + code + " had non-zero Content-Length: " + response.body().contentLength());
}
Run Code Online (Sandbox Code Playgroud)
如果您尝试返回标头中没有内容(服务器端)的内容,内容长度仍然大于 0;
任何非服务器端的想法如何解决这个问题?
我在春季启动中使用Rxjava2。
我在服务器上有500个并发请求。
每个请求产生10个线程,这些线程调用其他服务(因此IO工作)
因此,在这种情况下,我应该使用Schedulers.io()还是Schedulers.compuatation()。
基本上,我的困惑是理想上io()应该使用的,因为这是IO工作,但这会创建大量线程吗?
还可以指定计算线程的池大小吗?还可以指定io线程的池大小吗?