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;
}
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;
}
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;
}
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;
}
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);
}
Aggregations