List of usage examples for android.app Activity getSystemService
@Override
public Object getSystemService(@ServiceName @NonNull String name)
From source file:Main.java
/** * checks if there is network connection available * @param currentActivity/* ww w.j av a 2s . c o m*/ * @return */ public static boolean isMobileInternetAvailable(Activity currentActivity) { final ConnectivityManager connectivityManager = (ConnectivityManager) currentActivity .getSystemService(Context.CONNECTIVITY_SERVICE); final NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo(); if (networkInfo != null) { if (networkInfo.getType() == ConnectivityManager.TYPE_MOBILE) { if (networkInfo.isConnected()) { return true; } } } return false; }
From source file:Main.java
/** * Hide soft input from window./*from w ww . ja v a 2s . c o m*/ * @param activity */ public static void forceHideSoftInput(Activity activity) { try { InputMethodManager inputMethodManager = (InputMethodManager) activity .getSystemService(Activity.INPUT_METHOD_SERVICE); inputMethodManager.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), 0); } catch (Exception e) { } }
From source file:Main.java
public static void hideKeyboard(Activity activity) { if (activity != null) { InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE); if (imm != null && activity.getCurrentFocus() != null) { imm.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), 0); activity.getCurrentFocus().clearFocus(); }/* ww w .jav a 2s . co m*/ } }
From source file:Main.java
public static void hideSoftKeyboard(final Activity activity, final View input) { InputMethodManager inputMethodManager = (InputMethodManager) activity .getSystemService(Activity.INPUT_METHOD_SERVICE); if (inputMethodManager != null) { if (input != null) { IBinder windowToken = input.getWindowToken(); if (windowToken != null) { inputMethodManager.hideSoftInputFromWindow(windowToken, 0); }//from ww w.j ava 2s .co m } } }
From source file:Main.java
public static void hideKeyboard(Activity activity) { View view = activity.getCurrentFocus(); InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE); if (view == null) { return;//from w w w . j ava2 s. c om } imm.hideSoftInputFromWindow(view.getWindowToken(), 0); }
From source file:Main.java
public static void hideSoftKeyboard(Activity activity) { if (activity != null) { InputMethodManager inputMethodManager = (InputMethodManager) activity .getSystemService(Activity.INPUT_METHOD_SERVICE); View view = activity.getCurrentFocus(); if (view != null) inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0); }/*w w w .jav a2 s. co m*/ }
From source file:Main.java
public static void hideInput(Activity activity) { if (activity != null && activity.getCurrentFocus() != null) { ((InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow( activity.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); }// w ww .j a v a2 s . co m }
From source file:Main.java
public static void showKeyboard(Context context) { Activity activity = (Activity) context; if (activity != null) { InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE); imm.showSoftInputFromInputMethod(activity.getCurrentFocus().getWindowToken(), 0); imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS); }//from w w w.j a va 2 s. com }
From source file:Main.java
/** * Returns the size of the screen//from ww w .j av a2s . c o m * * @param activity The {@link Activity} to use * @return Point where x=width and y=height */ public static Point getScreenSize(Activity activity) { if (activity != null) { WindowManager service = (WindowManager) activity.getSystemService(Context.WINDOW_SERVICE); service.getDefaultDisplay().getSize(mScreenSize); } return mScreenSize; }
From source file:Main.java
private static void prepareBTAdapter(final Activity activity) { // Initializes Bluetooth adapter. BluetoothManager bluetoothManager = (BluetoothManager) activity.getSystemService(Context.BLUETOOTH_SERVICE); bluetoothAdapter = bluetoothManager.getAdapter(); }