小编Ken*_*mbo的帖子

如何在 Android 中测试活跃的互联网连接

我使用这种方法来 ping 谷歌服务器,这样我就可以检查活动internet连接,但我发现它并不适用于所有设备。

我尝试过使用其他方法,例如HttpURLConnectionandURLConnection但即使我已连接,它们也会返回 false。

任何适用于所有设备的想法或解决方案。提前致谢。我将连续发布我已经尝试过的内容。

方法一:

public static Boolean isOnline() {
    try {
        Process p1 = java.lang.Runtime.getRuntime().exec("ping -c 1 8.8.8.8");
        int returnVal = p1.waitFor();
        return (returnVal == 0);
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return false;
}
Run Code Online (Sandbox Code Playgroud)

我在本地和谷歌服务器上尝试过这个,它产生了完美的结果。问题是它不适用于所有设备。

方法二:

public boolean isConnected() {
    boolean connectivity;
    try {
        URL url = new URL("www.google.com");
        URLConnection conn = url.openConnection();
        conn.setConnectTimeout(5000);
        conn.connect();
        connectivity = true;
    } catch (Exception e) {
        connectivity …
Run Code Online (Sandbox Code Playgroud)

android internet-connection

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

Snackbar 在约束布局中与浮动操作栏重叠

我是第一次工作,constraint layout我想要实现的是snackbar在activity发布时展示。将snackbar被显示,但其重叠的我floating action menu。我已经尝试了一切,但没有任何效果。

我将发布我的 XML 和 Java,以便您告诉我可能是什么问题。我已经在网上尝试了所有解决方案,但没有任何效果。

这是xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:fab="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">

<android.support.v7.widget.RecyclerView
    android:id="@+id/ListViewCatalog"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_marginTop="?attr/actionBarSize"
    android:choiceMode="multipleChoice"
    android:clickable="true"
    android:focusable="true">

</android.support.v7.widget.RecyclerView>

<android.support.design.widget.CoordinatorLayout
    android:id="@+id/LinearLayout01"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_margin="5dip"
    android:orientation="horizontal">


    <com.github.clans.fab.FloatingActionMenu
        android:id="@+id/fab_menu"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:paddingBottom="@dimen/_10sdp"
        android:paddingEnd="@dimen/_16sdp"
        android:paddingRight="@dimen/_16sdp"
        fab:menu_fab_label="Pay"
        fab:fab_colorNormal="#DA4336"
        fab:fab_colorPressed="#E75043"
        fab:fab_colorRipple="#99FFFFFF"
        fab:fab_shadowColor="#66000000"
        fab:fab_showShadow="true"
        fab:menu_backgroundColor="#00000000"
        fab:menu_fab_hide_animation="@anim/fab_scale_up"
        fab:menu_fab_show_animation="@anim/fab_scale_down"
        fab:menu_labels_colorNormal="#333333"
        fab:menu_labels_colorPressed="#444444"
        fab:menu_labels_colorRipple="#66FFFFFF"
        fab:menu_labels_ellipsize="end"
        fab:menu_labels_maxLines="-1"
        fab:menu_labels_position="left"
        fab:menu_labels_showShadow="true"
        fab:menu_labels_singleLine="true"
        fab:menu_openDirection="up"
        tools:ignore="RtlSymmetry">

        <com.github.clans.fab.FloatingActionButton
            android:id="@+id/button02"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/add"
            fab:fab_label="Process"
            fab:fab_size="mini" />

        <com.github.clans.fab.FloatingActionButton …
Run Code Online (Sandbox Code Playgroud)

xml android android-layout android-constraintlayout floating-action-menu

5
推荐指数
1
解决办法
3811
查看次数