Example usage for android.app Activity getSystemService

List of usage examples for android.app Activity getSystemService

Introduction

In this page you can find the example usage for android.app Activity getSystemService.

Prototype

@Override
    public Object getSystemService(@ServiceName @NonNull String name) 

Source Link

Usage

From source file:Main.java

static void fireScreenCaptureIntent(Activity activity) {
    MediaProjectionManager manager = (MediaProjectionManager) activity
            .getSystemService(Context.MEDIA_PROJECTION_SERVICE);
    Intent intent = manager.createScreenCaptureIntent();
    activity.startActivityForResult(intent, CREATE_SCREENSHOT);
    Log.i("TakeScreenshotService", "fireScreenCaptureIntent...");
}

From source file:Main.java

public static void hideSoftInput(Activity mActivity, EditText editText) {
    InputMethodManager imm = (InputMethodManager) mActivity.getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);
}

From source file:Main.java

public static void closeInput(Activity activity) {
    InputMethodManager inputMethodManager = (InputMethodManager) activity
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    if (inputMethodManager != null && activity.getCurrentFocus() != null) {
        inputMethodManager.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(),
                InputMethodManager.HIDE_NOT_ALWAYS);
    }//from w  w w  . ja  v  a  2  s.  co  m
}

From source file:Main.java

public static void hideKeyboard(Activity act, View view) {
    InputMethodManager inputMethodManager = (InputMethodManager) act
            .getSystemService(Activity.INPUT_METHOD_SERVICE);
    inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
}

From source file:Main.java

public static boolean isNetworkAvailable(Activity activity) {
    ConnectivityManager connectivityManager = (ConnectivityManager) activity
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
    return activeNetworkInfo != null && activeNetworkInfo.isConnected();
}

From source file:Main.java

public static void hideSoftKeyboard(Activity activity) {
    InputMethodManager localInputMethodManager = (InputMethodManager) activity.getSystemService("input_method");
    IBinder localIBinder = activity.getWindow().getDecorView().getWindowToken();
    localInputMethodManager.hideSoftInputFromWindow(localIBinder, 0);
}

From source file:Main.java

/**
 * Remove the keyboard explicitly./*from  ww  w  .ja v  a 2  s. co  m*/
 */
public static void hideKeyBoard(Activity mActivity, View mGetView) {
    try {
        ((InputMethodManager) mActivity.getSystemService(Activity.INPUT_METHOD_SERVICE))
                .hideSoftInputFromWindow(mGetView.getRootView().getWindowToken(), 0);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static void vibrate(final Activity activity, long[] pattern, boolean isRepeat) {
    Vibrator vib = (Vibrator) activity.getSystemService(Service.VIBRATOR_SERVICE);
    vib.vibrate(pattern, isRepeat ? 1 : -1);
}

From source file:Main.java

public static int isNetworkAvailable(Activity act) {
    ConnectivityManager connectivityManager = (ConnectivityManager) act
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
    if (activeNetworkInfo != null && activeNetworkInfo.isConnected())
        return 1;
    else// w ww .j a  va 2 s  . co  m
        return 0;
}

From source file:Main.java

public static void Vibrate(final Activity activity, long[] pattern, boolean isRepeat) {
    Vibrator vib = (Vibrator) activity.getSystemService(Service.VIBRATOR_SERVICE);
    vib.vibrate(pattern, isRepeat ? 1 : -1);
}