我的请求应该获得POJO的JSON或JSON描述的错误(可能是无效的请求字段,服务器问题等).
但是订户的改造只给了我Throwable.我怎样才能发现网络错误,什么是http代码,并获得有错误的JSON?
private class ProjectListSubscriber extends Subscriber<ProjectListResponse> {
@Override
public void onCompleted() {
}
@Override
public void onError(Throwable e) {
//is that a network? http code? convert json to error POJO?
}
@Override
public void onNext(ProjectListResponse projectListResponse) {
updateProjectList(projectListResponse.getProjectList());
}
}
Run Code Online (Sandbox Code Playgroud) 我想测试一下,当我收到推送时,通知将会出现.也可以检查其属性(如标题,设置意图等).
我怎么能这样做?
@Before
public void setupTest() {
mData.putString(PushNotificator.KEY_PUSH_TYPE, PushType.PROJECT_OFFER.toString());
mData.putString(PushNotificator.KEY_PUSH_OBJECT, pushObjectJsonString);
mContext = InstrumentationRegistry.getContext();
}
@Test
public void projectOfferCreatedFromBundle() {
mPushNotificator = new PushNotificator(mContext);
mPushNotificator.processPush(mData);
onView(withText("111")).check(matches(withText("111"))); //how to find notification?
}
Run Code Online (Sandbox Code Playgroud) 我无法找到非google市场的新firebase 2.0功能的限制.
什么将在Firebase 1.0中起作用,什么在兼容模式下工作(线路分析,将从依赖库中增长服务,即使在设备上没有播放服务也能工作)以及缺点是什么,应该采取什么额外步骤为此工作,以及什么根本不起作用?
我有简单的要求
/*LOGIN*/
@FormUrlEncoded
@POST("v1/user/login") //your login function in your api
Call<LoginResponce> login(@Field("identity") String identity,
@Field("password") String password);
Run Code Online (Sandbox Code Playgroud)
如果http代码200,则返回LoginResponceobject
{"token":"itwbwKay7iUIOgT-GqnYeS_IXdjJi","user_id":17}
Run Code Online (Sandbox Code Playgroud)
或错误Json,如果出现问题则描述确切的错误
{"status":4,"description":"user provided token expired"}
Run Code Online (Sandbox Code Playgroud)
如何处理响应中的错误状态?
我试过这个,但它没有在原始文本中看到JSON(doens't工作).而且似乎不是很好的解决方案.
mCallLoginResponse.enqueue(new Callback<LoginResponce>() {
@Override
public void onResponse(Response<LoginResponce> response, Retrofit retrofit) {
if (response.isSuccess()) {
registerWithToken(response.body().getToken());
} else { //some error in responce
Gson gson = new GsonBuilder().create();
ApiError mApiError = gson.fromJson(response.raw().body().toString(),
ApiError.class); //Exception here - no JSON in String
//todo error handling
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个包含多个模块的 android 项目,模块 B 依赖于模块 A
dependencies {
implementation project(':features:A')
}
Run Code Online (Sandbox Code Playgroud)
我希望模块 B 中的单元测试扩展模块 A 的基础测试。IDE 成功解析了所有依赖项,但在构建时,只有模块 A 的生产代码可在测试中访问。
我尝试专门为测试添加依赖项:
dependencies {
testCompile project(':features:A').sourceSets.test.output
}
Run Code Online (Sandbox Code Playgroud)
这会导致错误:
Could not get unknown property 'test' for SourceSet container of type org.gradle.api.internal.tasks.DefaultSourceSetContainer.
Run Code Online (Sandbox Code Playgroud)
如果我尝试使用测试创建自定义工件,也是如此。
如何从依赖模块访问基本模块中特定于测试的代码?
AS 3.1,gradle 4.1
android gradle android-studio build.gradle android-gradle-plugin
我正在努力寻找
@BindView($ResId) internal lateinit var $FieldName: $Class
Run Code Online (Sandbox Code Playgroud)
并替换为
private val $FieldName by bindView<$Class>($ResId)
Run Code Online (Sandbox Code Playgroud)
使用 Intellij 查找和替换功能执行此操作的语法是什么?
如果我定义一个像 的依赖项foo = { version = "1.0.0", optional = true }
,当我执行“cargo run”时它会可用吗?我可以检查它是否在代码中启用吗?
if cfg!(feature = "foo") {}
Run Code Online (Sandbox Code Playgroud)
似乎不起作用,就像该功能一直缺失一样。
设计师经常通过将“我们的”自定义主题中的现有颜色放在另一个应用了 Alpha 的顶部来构建自定义颜色。如何在不应用多个背景的情况下计算结果颜色?就像是
val background = MaterialTheme.colors.MyDanger.copy(alpha = 0.12f) + MaterialTheme.colors.CustomTint16
Run Code Online (Sandbox Code Playgroud)
Plus 没有为颜色定义,因为它不是可交换的,但是有没有办法在代码中将一种颜色放在另一种颜色之上并仅应用结果?
我有一个代码示例:
mediaRecorder = new MediaRecorder();
mediaRecorder.setPreviewDisplay(surfaceHolder.getSurface());
mediaRecorder.setCamera(camera);
mediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
mediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
mediaRecorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_480P));
Run Code Online (Sandbox Code Playgroud)
这似乎工作正常,以及 CamcorderProfile.QUALITY_LOW
但是当我尝试获取 360p 视频并使用 CamcorderProfile.QUALITY_CIF (int = 3) 时,我在 Sony Xperia Z3 (android 6.0.1) 中出现错误
MediaProfiles: The given camcorder profile camera 0 quality 3 is not found
System.err: java.lang.RuntimeException: Error retrieving camcorder profile params
System.err: at android.media.CamcorderProfile.native_get_camcorder_profile(Native Method)
System.err: at android.media.CamcorderProfile.get(CamcorderProfile.java:471)
System.err: at android.media.CamcorderProfile.get(CamcorderProfile.java:402)
<...>
Run Code Online (Sandbox Code Playgroud)
AOSP 测试套件还没有测试 SDK 相机质量常数吗?我可以在生产中使用哪些常量并期望所有手机(至少从 5.0 开始)都支持它?