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

/**
 * Show the activity over the lockscreen and wake up the device. If you
 * launched the app manually both of these conditions are already true. If
 * you deployed from the IDE, however, this will save you from hundreds of
 * power button presses and pattern swiping per day!
 *///from w  w  w  . ja v  a2s .c o  m
public static void riseAndShine(Activity activity) {
    activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);

    PowerManager power = (PowerManager) activity.getSystemService(Context.POWER_SERVICE);
    PowerManager.WakeLock lock = power.newWakeLock(
            PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE,
            "wakeup!");

    lock.acquire();
    lock.release();
}

From source file:Main.java

/**
 * This method stops the tracking notification for the user.
 * /*from w ww  .ja  va2  s.  c o m*/
 * @param activity
 *            The activity from which the method called.
 */
public static void stopUserNotification(Activity activity) {
    String ns = Context.NOTIFICATION_SERVICE;
    NotificationManager mNotificationManager = (NotificationManager) activity.getSystemService(ns);
    mNotificationManager.cancel(TRACKING_NOTIFY_ID);

}

From source file:de.baumann.quitsmoking.helper.helper_main.java

public static void showKeyboard(Activity from, EditText editText) {
    InputMethodManager imm = (InputMethodManager) from.getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);
    editText.setSelection(editText.length());
}

From source file:Main.java

public static boolean checkConnection(Activity a) {
    boolean hasConnectedWifi = false;
    boolean hasConnectedMobile = false;

    ConnectivityManager cm = (ConnectivityManager) a.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo[] netInfo = cm.getAllNetworkInfo();
    for (NetworkInfo ni : netInfo) {
        if (ni.getTypeName().equalsIgnoreCase("wifi"))
            if (ni.isConnected())
                hasConnectedWifi = true;
        if (ni.getTypeName().equalsIgnoreCase("mobile"))
            if (ni.isConnected())
                hasConnectedMobile = true;
    }//from  w  w  w .ja  va 2  s  .  com
    return hasConnectedWifi || hasConnectedMobile;
}

From source file:Main.java

public static void hideInput(Activity activity) {
    View view = activity.getWindow().peekDecorView();
    if (view != null) {
        InputMethodManager inputmanger = (InputMethodManager) activity
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        inputmanger.hideSoftInputFromWindow(view.getWindowToken(), 0);
    }/*from   w w w .j av a  2s  .  c  o m*/
}

From source file:Main.java

/**
 * Checks whether the device is connected to a network
 *///from w w w  .  j  a  v a2 s. c  o  m
public static boolean hasInternet(Activity a) {
    boolean hasConnectedWifi = false;
    boolean hasConnectedMobile = false;

    ConnectivityManager cm = (ConnectivityManager) a.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo[] netInfo = cm.getAllNetworkInfo();
    for (NetworkInfo ni : netInfo) {
        if (ni.getTypeName().equalsIgnoreCase("wifi"))
            if (ni.isConnected())
                hasConnectedWifi = true;
        if (ni.getTypeName().equalsIgnoreCase("mobile"))
            if (ni.isConnected())
                hasConnectedMobile = true;
    }
    return hasConnectedWifi || hasConnectedMobile;
}

From source file:Main.java

public static void hideKeyboard(Activity activity, View view) {
    if (activity != null) {
        if (view != null) {
            InputMethodManager imm = (InputMethodManager) activity
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            if (imm != null) {
                imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
            }/* w  ww.  j  a v  a  2  s.c  o  m*/
        } else {
            hideKeyboard(activity);
        }
    }
}

From source file:Main.java

public static void hideSoftInput(Activity activity) {
    View view = activity.getCurrentFocus();
    if (view != null) {
        InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
    }/*  ww w . ja v  a 2s.  co  m*/
}

From source file:com.microsoft.mimickeralarm.mimics.MimicFactory.java

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

From source file:Main.java

@TargetApi(Build.VERSION_CODES.CUPCAKE)
public static void hideSoftInput(Activity activity) {
    View view = activity.getWindow().peekDecorView();
    if (view != null) {
        InputMethodManager inputmanger = (InputMethodManager) activity
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        inputmanger.hideSoftInputFromWindow(view.getWindowToken(), 0);
    }//from   w ww .  j  a  va2s .  c om
}