Example usage for android.app Application getSystemService

List of usage examples for android.app Application getSystemService

Introduction

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

Prototype

@Override
    public Object getSystemService(String name) 

Source Link

Usage

From source file:Main.java

public static void init(Application application) {
    sClipboardManager = (ClipboardManager) application.getSystemService(Context.CLIPBOARD_SERVICE);
}

From source file:Main.java

public static String getCurrentWifiIP(Application app) {
    WifiManager wifiManager = (WifiManager) app.getSystemService(Application.WIFI_SERVICE);
    if (!wifiManager.isWifiEnabled()) {
        return null;
    }/*from   w  ww. j a  va 2s .c o m*/

    WifiInfo wifiInfo = wifiManager.getConnectionInfo();

    int ipAddress = wifiInfo.getIpAddress();
    String strIPAddess = ((ipAddress >> 0) & 0xFF) + "." + ((ipAddress >> 8) & 0xFF) + "."
            + ((ipAddress >> 16) & 0xFF) + "." + ((ipAddress >> 24) & 0xFF);

    return strIPAddess;
}

From source file:app.presentation.foundation.gcm.GcmReceiverBackground.java

private void showNotification(Message message, String title, String body, Application application) {
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(application)
            .setContentTitle(title).setContentText(body).setDefaults(Notification.DEFAULT_ALL)
            .setSmallIcon(R.mipmap.ic_launcher).setAutoCancel(true)
            .setContentIntent(getPendingIntentForNotification(message));

    NotificationManager notificationManager = (NotificationManager) application
            .getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(1, notificationBuilder.build());
}

From source file:net.wequick.small.Small.java

public static void preSetUp(Application context) {
    sContext = context;//from w w  w  .  j a va  2s  .  c o m

    // Register default bundle launchers
    registerLauncher(new ActivityLauncher());
    registerLauncher(new ApkBundleLauncher());
    registerLauncher(new WebBundleLauncher());

    PackageManager pm = context.getPackageManager();
    String packageName = context.getPackageName();

    // Check if host app is first-installed or upgraded
    int backupHostVersion = getHostVersionCode();
    int currHostVersion = 0;
    try {
        PackageInfo pi = pm.getPackageInfo(packageName, 0);
        currHostVersion = pi.versionCode;
    } catch (PackageManager.NameNotFoundException ignored) {
        // Never reach
    }

    if (backupHostVersion != currHostVersion) {
        sIsNewHostApp = true;
        setHostVersionCode(currHostVersion);
    } else {
        sIsNewHostApp = false;
    }

    // Collect host certificates
    try {
        Signature[] ss = pm.getPackageInfo(Small.getContext().getPackageName(),
                PackageManager.GET_SIGNATURES).signatures;
        if (ss != null) {
            int N = ss.length;
            sHostCertificates = new byte[N][];
            for (int i = 0; i < N; i++) {
                sHostCertificates[i] = ss[i].toByteArray();
            }
        }
    } catch (PackageManager.NameNotFoundException ignored) {

    }

    // Check if application is started after unexpected exit (killed in background etc.)
    ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    ComponentName launchingComponent = am.getRunningTasks(1).get(0).topActivity;
    ComponentName launcherComponent = pm.getLaunchIntentForPackage(packageName).getComponent();
    if (!launchingComponent.equals(launcherComponent)) {
        // In this case, system launching the last restored activity instead of our launcher
        // activity. Call `setUp' synchronously to ensure `Small' available.
        setUp(context, null);
    }
}