我是新的Android编码器,我在请求更新我的本地化时遇到问题.
我使用http://developer.android.com/training/location/receive-location-updates.html上的教程.
我的应用程序可以处理异常,正确获取纬度和长度,地理编码器可以处理显示地址.但我只询问一次位置 - 或者当位置发生变化时.我想做一些时间间隔.现在我开始实现教程中的代码,它看起来像这样:
public class MainActivity extends Activity implements
GooglePlayServicesClient.ConnectionCallbacks,
GooglePlayServicesClient.OnConnectionFailedListener,
LocationListener {
private static final int MILLISECONDS_PER_SECOND = 1000;
public static final int UPDATE_INTERVAL_IN_SECONDS = 5;
private static final long UPDATE_INTERVAL =
MILLISECONDS_PER_SECOND * UPDATE_INTERVAL_IN_SECONDS;
private static final int FASTEST_INTERVAL_IN_SECONDS = 1;
private static final long FASTEST_INTERVAL =
MILLISECONDS_PER_SECOND * FASTEST_INTERVAL_IN_SECONDS;
private TextView tvStatus;
private TextView tvLatitude;
private TextView tvLongitude;
LocationRequest mLocationRequest;
LocationClient mLocationClient;
Location mCurrentLocation;
boolean bNetworkEnabled;
boolean bGPSEnabled;
@Override
protected void onCreate(Bundle savedInstanceState) …Run Code Online (Sandbox Code Playgroud) 我的apiPath是完全动态的.我正在使用包含"ipAddress"和"SSLprotocol"等字段的项目.基于它们我可以建立我的网址:
private String urlBuilder(Server server) {
String protocol;
String address = "";
if (AppTools.isDeviceOnWifi(activity)) {
address = serverToConnect.getExternalIp();
} else if (AppTools.isDeviceOnGSM(activity)) {
address = serverToConnect.getInternalIp();
}
if (server.isShouldUseSSL()) {
protocol = "https://";
} else {
protocol = "http://";
}
return protocol + address;
}
Run Code Online (Sandbox Code Playgroud)
所以我的协议+地址可以是:http:// + 192.168.0.01:8010 = http://192.168.0.01:8010
我想这样使用它:
@FormUrlEncoded
@POST("{fullyGeneratedPath}/json/token.php")
Observable<AuthenticationResponse> authenticateUser(
@Path("fullyGeneratedPath") String fullyGeneratedPath,
@Field("login") String login,
@Field("psw") String password,
@Field("mobile") String mobile);
Run Code Online (Sandbox Code Playgroud)
因此,authenticateUser的完整路径将是http://192.168.0.01:8010/json/token.php - 例如.
这意味着我不需要任何basePath,因为我自己创建整个basePath,具体取决于我想要连接的服务器.
我的改造设置是:
@Provides
@Singleton
Retrofit provideRetrofit(OkHttpClient okHttpClient,
Converter.Factory converterFactory, …Run Code Online (Sandbox Code Playgroud) 我正在使用Android Espresso.我需要espresso-web才能使用webview.我根据谷歌网站设置了浓缩咖啡.
https://google.github.io/android-testing-support-library/downloads/index.html
我的依赖关系看起来像这样:
dependencies {
androidTestCompile 'junit:junit:4.12'
androidTestCompile 'com.squareup.spoon:spoon-client:1.1.10'
androidTestCompile 'com.jraska:falcon-spoon-compat:0.3.1'
androidTestCompile 'com.android.support:support-annotations:23.1.1'
androidTestCompile 'com.android.support.test:runner:0.4.1'
androidTestCompile 'com.android.support.test:rules:0.4.1'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.1'
androidTestCompile 'com.android.support.test.espresso:espresso-web:2.2.1'
androidTestCompile "org.mockito:mockito-core:1.10.19"
androidTestCompile "com.google.dexmaker:dexmaker:1.2"
androidTestCompile "com.google.dexmaker:dexmaker-mockito:1.2"
}
Run Code Online (Sandbox Code Playgroud)
当我评论espresso-web导入/方法并排除此lib时,测试运行.但有了它,我得到:
Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForDebugAndroidTest'.
> com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK META-INF/maven/com.google.guava/guava/pom.properties
File1: /Users/F1sherKK/Dev/MyProject/app/build/intermediates/exploded-aar/com.android.support.test.espresso/espresso-web/2.2.1/jars/classes.jar
File2: /Users/F1sherKK/Dev/MyProject/app/build/intermediates/exploded-aar/com.android.support.test.espresso/espresso-core/2.2.1/jars/classes.jar
Run Code Online (Sandbox Code Playgroud)
似乎是番石榴的一些问题.Espress-web lib生成两个文件夹:espresso-web,espresso-core.Espresso-core lib也生成espresso-core,它们似乎重叠 - 但这就是设置应该如何.排除Espresso核心库并没有帮助.知道怎么解决吗?
编辑:
目前在packagingOptions中的解决方法:
exclude 'META-INF/maven/com.google.guava/guava/pom.properties'
exclude 'META-INF/maven/com.google.guava/guava/pom.xml'
Run Code Online (Sandbox Code Playgroud) 我正在研究虚拟机,所以我无法复制代码......然后我将发布屏幕.问题是微不足道的我想但我不能处理它...请给我一些建议:
表代码:https: //dl.dropboxusercontent.com/u/108321090/WWW1.png
CSS代码和网站视线:https: //dl.dropboxusercontent.com/u/108321090/WWW.png
所以一般情况下,你可以在第二个链接上看到,行中有一个文本,它不需要包装,它一直作为通道进入并离开表列边界.
您好我正在观察我的服务器每15秒询问其在线/离线状态:
public Observable<Response> repeatCheckServerStatus(int intervalSec, final String path) {
return Observable.interval(intervalSec, TimeUnit.SECONDS)
.flatMap(new Func1<Long, Observable<Response>>() {
@Override
public Observable<Response> call(Long aLong) {
return Observable.create(new Observable.OnSubscribe<Response>() {
@Override
public void call(Subscriber<? super Response> subscriber) {
try {
Response response = client.newCall(new Request.Builder()
.url(path + API_ACTION_CHECK_ONLINE_STATUS)
.header("Content-Type", "application/x-www-form-urlencoded")
.get()
.build()).execute();
subscriber.onNext(response);
subscriber.onCompleted();
if (!response.isSuccessful())
subscriber.onError(new Exception());
} catch (Exception e) {
subscriber.onError(e);
}
}
})
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread());
}
});
}
Run Code Online (Sandbox Code Playgroud)
在我调用此方法之后,首先执行代码将在intervalSec时间之后(在我的情况下为15秒).查看区间方法的rxJava文档:
http://reactivex.io/documentation/operators/interval.html
这应该是这样的.
问题:有没有办法立即执行代码然后重复间隔?
我需要在Jupyter Notebook中渲染一些html表,为此我已经定义了自己的css样式.我希望它可以在任何PC上重复使用.
现在我需要在一个Jupyter单元格中运行这样的代码:
%%html
<style>
.output_wrapper, .output {
height:auto !important;
max-height: none;
}
.output_scroll {
box-shadow:none !important;
webkit-box-shadow:none !important;
}
.package_header {
width: 100%;
background-color: #0e2b59;
color: #ffffff;
font-size: 14px;
text-align: center;
padding-top: 8px;
padding-right: 8px;
padding-bottom: 8px;
padding-left: 8px;
}
.placeholder {
width: 100%;
background-color: #ffffff;
height: 6px;
}
.passed_test_table {
display: table;
width: 100%;
background-color: #ebffd3;
border-spacing: 5px;
}
# (...) rest of css classes omitted
</style>
Run Code Online (Sandbox Code Playgroud)
然而,我不想将它存储style在Jupyter Notebook中,而是存储在my_default_style.css等其他文件中,并以某种方式加载它,因此它不会占用太多空间,使得它的可读性降低.
是否可以从某些本地文件加载.css样式而不是直接在Jupyter Notebook单元格中运行它?
我从git最新的zBar QR Code Scanner(SDK 0.2)下载了.我试图在我的应用程序中实现它.我在Android Studio上工作.
我做了什么:
无需更改gradle中的任何内容,因为它已配置为从libs项目导入每个jar文件.见下文:
dependencies {
compile 'com.android.support:support-v4:18.0.+'
compile 'com.crashlytics.android:crashlytics:1.+'
compile fileTree(dir: 'libs', include: '*.jar')
compile project(':FacebookSDK')
compile project(':actionbarsherlock')
compile project(':Aviary-SDK')
}
Run Code Online (Sandbox Code Playgroud)可以看到每个类形式的zBar lib,所以我已经配置了所有内容.我运行我的ScannerActivity并在onCreate中我得到错误:
scanner = new ImageScanner(); // this line shows an error
scanner.setConfig(0, Config.X_DENSITY, 3);
scanner.setConfig(0, Config.Y_DENSITY, 3);
Run Code Online (Sandbox Code Playgroud)因此实现与示例中的1:1相同.
我的错误日志:
java.lang.UnsatisfiedLinkError: Couldn't load zbarjni from loader dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/pl.toptof.android.debug-2.apk"],nativeLibraryDirectories=[/data/app-lib/pl.toptof.android.debug-2, /vendor/lib, /system/lib]]]: findLibrary returned null
Run Code Online (Sandbox Code Playgroud)
请帮我解决这个问题.我不知道为什么我的Android Studio可以看到lib,但不能像在示例中那样使用它.
我正在使用Espresso 2.2编写仪器测试.
流程我想测试:
我想在点击radioButton后注册IdleResource,等待vSetupAmount变为可见.但我不能让它发挥作用.请告诉我我做错了什么.
我写过这样的IdleResource:
public class AmountViewIdlingResource implements IdlingResource {
private CountriesAndRatesActivity activity;
private ResourceCallback callback;
private SetupAmountView amountView;
public AmountViewIdlingResource(CountriesAndRatesActivity activity) {
this.activity = activity;
amountView = (SetupAmountView) this.activity.findViewById(R.id.vSetupAmount);
}
@Override public String getName() {
return "Amount View idling resource";
}
@Override public boolean isIdleNow() {
callback.onTransitionToIdle();
return amountView.getVisibility() == View.VISIBLE;
}
@Override public void registerIdleTransitionCallback(ResourceCallback resourceCallback) {
this.callback = resourceCallback;
}
}
Run Code Online (Sandbox Code Playgroud)
所以我将活动传递给IdleResource,链接视图与变量.我知道IdleResource将不会让测试通过,直到isIdleNow()返回值true.因此,如果视图是View.GONE,那么它将不会更进一步.
它在测试中看起来如何:
// click of radioButton picked from radioGroup
onView(withId(rgDeliveries.getChildAt(id).getId())).perform(scrollTo(), …Run Code Online (Sandbox Code Playgroud) 是否可以通过Espresso执行拖放操作?我需要向下移动一个视图(直线)以接受我的自动化测试中的某些条件.