小编Uba*_*hat的帖子

使用android espresso测试带有多个片段的ViewPager

我正在尝试测试我使用的应用程序ViewPager.每个页面都包含片段,但这些片段并不总是可见.我想检查当前可见页面中片段的可见性.

onView(withId(R.id.container_weather))
    .check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)));
Run Code Online (Sandbox Code Playgroud)

但问题是espresso外观不仅是当前页面的所有页面而且我收到以下错误:

android.support.test.espresso.AmbiguousViewMatcherException:'with id:eu.airpatrol.android:id/container_weather'匹配层次结构中的多个视图...

android automated-tests android-espresso

9
推荐指数
2
解决办法
5334
查看次数

SwipeRefreshLayout获得了ACTION_MOVE事件,但没有活动指针ID

我正在使用SwipeRefreshLayout和AppCompat ListFragment.我拉动刷新似乎工作正常但有时在日志中我可以看到以下错误.如果我在刷新或刚刚完成刷新时再次拉动列表,则会发生这种情况.

E/SwipeRefreshLayout: Got ACTION_MOVE event but don't have an active pointer id.
Run Code Online (Sandbox Code Playgroud)

我的布局代码是:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

    <android.support.v4.widget.SwipeRefreshLayout
            android:id="@+id/activity_main_swipe_refresh_layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <ListView
                android:id="@id/android:list"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:overScrollMode="never"
                />
    </android.support.v4.widget.SwipeRefreshLayout>
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)

在ListFragment中,我重写onCreateView

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);

    View view = inflater.inflate(R.layout.list_layout, container, false);


    swipeRefreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.activity_main_swipe_refresh_layout);
    swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            log.d("swipeRefreshLayout onRefresh");
            onRefreshList();
        }
    });

    adapter = new ItemAdapter(getActivity());
    setListAdapter(adapter);
    return view;
}
Run Code Online (Sandbox Code Playgroud)

android

8
推荐指数
1
解决办法
2107
查看次数

在shouldInterceptRequest Android webview中为所有请求添加自定义标头

我想在webview中为请求添加自定义标头.我认为应该可以这样做shouldInterceptRequest..因为我的最小API级别小于21 shouldInterceptRequest(最终的WebView视图,最终的String url)也被调用,因此我需要在这里添加标题,但我不知道如何.

@Override
public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            request.getRequestHeaders().put("ClientId", "ANDROID");
            request.getRequestHeaders().put("Tokon", token);
        }

        return super.shouldInterceptRequest(view, request);
    }

    @Override
    public WebResourceResponse shouldInterceptRequest(final WebView view, final String url) {
        // I need to updated the header here

        return super.shouldInterceptRequest(view, url);
    }
Run Code Online (Sandbox Code Playgroud)

有一个建议使用view.loadUrl(url,headers),但这也不起作用.

android webview

7
推荐指数
1
解决办法
4770
查看次数

Android Espresso 测试中的存根/模拟意图

我想在我的应用程序中测试以下流程:

  1. 用户单击扫描按钮
  2. onClick 启动了 ZXing 应用程序
  3. 如果返回正确的二维码,我们继续,否则用户可以选择手动输入二维码

我想用浓缩咖啡测试这个流程。我想我必须使用意图或意图1,但我不确定如何检查意图是否为 ZXing 以及如何返回应用程序。

java stubbing zxing android-espresso

6
推荐指数
1
解决办法
2710
查看次数

使用java中的方法避免!= null

在我的下面的例子中,我想避免每次我想使用getView时编写getView!= null.为了保持清洁,我创建了一个方法hasView()来检查我.但是我仍然收到警告.有没有办法解决?

import android.support.annotation.Nullable;

public void showView(){
    if(hasView()){
        getView().show(); // Shows warning Method invocation 'showLoading' may produce 'java.lang.NullPointerException'
    }
}


boolean hasView(){
    return getView() != null;
}

@Nullable
private View getView(){
    return view;
}
Run Code Online (Sandbox Code Playgroud)

我正在使用Android Studio/IntelliJ.我知道我可以使用@SuppressWarnings 我已经看到了这个问题,但是这使代码变得更加丑陋.

java android intellij-idea

4
推荐指数
1
解决办法
162
查看次数

使用 adb 卸载多个 android 软件包

我正在尝试使用带有 adb uninstall 的 bash 脚本卸载多个软件包。

理论上,以下脚本应该可以工作:

adb shell pm list packages com.your.app |
cut -d ':' -f 2 | while read line ; do
  adb uninstall --verbose $line
done
Run Code Online (Sandbox Code Playgroud)

或者

adb shell pm list packages com.your.app |
cut -d ':' -f 2 |
xargs -L1 -t adb uninstall
Run Code Online (Sandbox Code Playgroud)

我收到以下错误

失败 [DE​​LETE_FAILED_INTERNAL_ERROR]

我还发现问题在于 adb 命令没有从 shell 变量中获取管道参数或参数。例如下面的命令也

echo com.your.app | adb uninstall
Run Code Online (Sandbox Code Playgroud)

这也会产生同样的错误。

我已经看过通过 adb shell pm 删除域的包

bash shell android adb

2
推荐指数
1
解决办法
4474
查看次数