Search in sources :

Example 36 with ConnectivityManager

use of android.net.ConnectivityManager in project android-app by eoecn.

the class APNManager method getDefaultNetworkType.

public int getDefaultNetworkType() {
    int networkType = -1;
    ConnectivityManager connectivity = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
    if (connectivity == null) {
    } else {
        // wifi network have priority
        NetworkInfo wifiNetworkInfo = connectivity.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
        if (wifiNetworkInfo != null && wifiNetworkInfo.getState() == NetworkInfo.State.CONNECTED) {
            return ConnectivityManager.TYPE_WIFI;
        }
        NetworkInfo[] info = connectivity.getAllNetworkInfo();
        for (int i = 0; i < info.length; i++) {
            if (info[i].getState() == NetworkInfo.State.CONNECTED) {
                // use first available network
                networkType = info[i].getType();
                break;
            }
        }
    }
    return networkType;
}
Also used : NetworkInfo(android.net.NetworkInfo) ConnectivityManager(android.net.ConnectivityManager)

Example 37 with ConnectivityManager

use of android.net.ConnectivityManager in project android-app by eoecn.

the class NetWorkHelper method isWifiDataEnable.

/**
	 * 判断wifi 是否可用
	 * @param context
	 * @return
	 * @throws Exception
	 */
public static boolean isWifiDataEnable(Context context) throws Exception {
    ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    boolean isWifiDataEnable = false;
    isWifiDataEnable = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnectedOrConnecting();
    return isWifiDataEnable;
}
Also used : ConnectivityManager(android.net.ConnectivityManager)

Example 38 with ConnectivityManager

use of android.net.ConnectivityManager in project android-app by eoecn.

the class NetWorkHelper method isMobileDataEnable.

/**
	 * 判断MOBILE网络是否可用
	 * 
	 * @param context
	 * @return
	 * @throws Exception
	 */
public static boolean isMobileDataEnable(Context context) throws Exception {
    ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    boolean isMobileDataEnable = false;
    isMobileDataEnable = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).isConnectedOrConnecting();
    return isMobileDataEnable;
}
Also used : ConnectivityManager(android.net.ConnectivityManager)

Example 39 with ConnectivityManager

use of android.net.ConnectivityManager in project android-job by evernote.

the class Device method getNetworkType.

@NonNull
public static JobRequest.NetworkType getNetworkType(Context context) {
    ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
    if (networkInfo == null || !networkInfo.isConnectedOrConnecting()) {
        return JobRequest.NetworkType.ANY;
    }
    TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    if (telephonyManager != null && telephonyManager.isNetworkRoaming()) {
        return JobRequest.NetworkType.CONNECTED;
    }
    boolean metered = ConnectivityManagerCompat.isActiveNetworkMetered(connectivityManager);
    return metered ? JobRequest.NetworkType.NOT_ROAMING : JobRequest.NetworkType.UNMETERED;
}
Also used : NetworkInfo(android.net.NetworkInfo) TelephonyManager(android.telephony.TelephonyManager) ConnectivityManager(android.net.ConnectivityManager) NonNull(android.support.annotation.NonNull)

Example 40 with ConnectivityManager

use of android.net.ConnectivityManager in project materialistic by hidroh.

the class ItemFragmentSinglePageTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    TestApplication.applicationGraph.inject(this);
    reset(hackerNewsClient);
    reset(userServices);
    shadowOf(((WindowManager) RuntimeEnvironment.application.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay()).setHeight(// no preload
    0);
    shadowOf((ConnectivityManager) RuntimeEnvironment.application.getSystemService(Context.CONNECTIVITY_SERVICE)).setActiveNetworkInfo(ShadowNetworkInfo.newInstance(null, ConnectivityManager.TYPE_WIFI, 0, true, true));
    final TestHnItem item0 = new TestHnItem(1, 1) {

        @Override
        public long getNeighbour(int direction) {
            if (direction == Navigable.DIRECTION_DOWN) {
                return 4L;
            }
            return super.getNeighbour(direction);
        }
    };
    item0.populate(new // level 0
    TestItem() {

        @Override
        public String getId() {
            return "1";
        }

        @Override
        public String getText() {
            return "text";
        }

        @Override
        public int getDescendants() {
            return 1;
        }

        @Override
        public long[] getKids() {
            return new long[] { 2L };
        }
    });
    final TestHnItem item1 = new TestHnItem(2, 2);
    item1.populate(new // level 1
    TestItem() {

        @Override
        public String getId() {
            return "2";
        }

        @Override
        public String getParent() {
            return "1";
        }

        @Override
        public boolean isDeleted() {
            return true;
        }

        @Override
        public String getText() {
            return "text";
        }

        @Override
        public int getDescendants() {
            return 1;
        }

        @Override
        public long[] getKids() {
            return new long[] { 3L };
        }
    });
    item0.getKidItems()[0] = item1;
    final TestHnItem item2 = new TestHnItem(3, 3);
    item2.populate(new // level 2
    TestItem() {

        @Override
        public String getId() {
            return "3";
        }

        @Override
        public long[] getKids() {
            return new long[0];
        }

        @Override
        public int getDescendants() {
            return 0;
        }

        @Override
        public String getParent() {
            return "2";
        }

        @Override
        public boolean isDead() {
            return true;
        }
    });
    item1.getKidItems()[0] = item2;
    TestHnItem item3 = new TestHnItem(4, 4) {

        @Override
        public long getNeighbour(int direction) {
            if (direction == Navigable.DIRECTION_UP) {
                return 1L;
            }
            return super.getNeighbour(direction);
        }
    };
    item3.populate(new // level 0
    TestItem() {

        @Override
        public String getId() {
            return "4";
        }

        @Override
        public String getText() {
            return "text";
        }

        @Override
        public int getDescendants() {
            return 0;
        }

        @Override
        public long[] getKids() {
            return new long[0];
        }
    });
    TestHnItem story = new TestHnItem(0);
    story.populate(new TestItem() {

        @Override
        public long[] getKids() {
            return new long[] { 1L, 4L };
        }

        @Override
        public int getDescendants() {
            return 4;
        }
    });
    story.getKidItems()[0] = item0;
    story.getKidItems()[1] = item3;
    Bundle args = new Bundle();
    args.putParcelable(ItemFragment.EXTRA_ITEM, story);
    fragment = (ItemFragment) Fragment.instantiate(RuntimeEnvironment.application, ItemFragment.class.getName(), args);
    controller = Robolectric.buildActivity(ItemFragmentMultiPageTest.TestItemActivity.class);
    activity = controller.create().start().resume().visible().get();
    PreferenceManager.getDefaultSharedPreferences(activity).edit().putBoolean(activity.getString(R.string.pref_lazy_load), false).apply();
    activity.getSupportFragmentManager().beginTransaction().add(R.id.content_frame, fragment, ItemFragment.class.getName()).commit();
    recyclerView = (RecyclerView) fragment.getView().findViewById(R.id.recycler_view);
    adapter = (SinglePageItemRecyclerViewAdapter) recyclerView.getAdapter();
    // auto expand all
    viewHolder = (ToggleItemViewHolder) customShadowOf(adapter).getViewHolder(0);
    viewHolder1 = (ToggleItemViewHolder) customShadowOf(adapter).getViewHolder(1);
    viewHolder2 = (ToggleItemViewHolder) customShadowOf(adapter).getViewHolder(2);
}
Also used : ConnectivityManager(android.net.ConnectivityManager) Bundle(android.os.Bundle) TestHnItem(io.github.hidroh.materialistic.data.TestHnItem) WindowManager(android.view.WindowManager) TestItem(io.github.hidroh.materialistic.test.TestItem) Before(org.junit.Before)

Aggregations

ConnectivityManager (android.net.ConnectivityManager)379 NetworkInfo (android.net.NetworkInfo)275 Context (android.content.Context)14 TelephonyManager (android.telephony.TelephonyManager)14 Intent (android.content.Intent)11 RemoteException (android.os.RemoteException)11 Test (org.junit.Test)11 WifiManager (android.net.wifi.WifiManager)9 Method (java.lang.reflect.Method)9 Network (android.net.Network)8 IOException (java.io.IOException)8 PackageManager (android.content.pm.PackageManager)7 UserManager (android.os.UserManager)7 SharedPreferences (android.content.SharedPreferences)6 NetworkCapabilities (android.net.NetworkCapabilities)6 Activity (android.app.Activity)5 ApplicationInfo (android.content.pm.ApplicationInfo)5 IPackageManager (android.content.pm.IPackageManager)5 PackageInfo (android.content.pm.PackageInfo)5 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)5