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:biz.wiz.android.wallet.ui.WalletAddressFragment.java

@Override
public void onAttach(final Activity activity) {
    super.onAttach(activity);

    this.activity = activity;
    this.application = (WalletApplication) activity.getApplication();
    this.wallet = application.getWallet();
    this.loaderManager = getLoaderManager();
    final NfcManager nfcManager = (NfcManager) activity.getSystemService(Context.NFC_SERVICE);
    this.nfcAdapter = nfcManager.getDefaultAdapter();
}

From source file:com.example.android.apprestrictionenforcer.AppRestrictionEnforcerFragment.java

/**
 * Saves all the restrictions./*from  w ww  .j av  a2 s .c o  m*/
 *
 * @param activity The activity.
 */
private void saveRestrictions(Activity activity) {
    DevicePolicyManager devicePolicyManager = (DevicePolicyManager) activity
            .getSystemService(Context.DEVICE_POLICY_SERVICE);
    devicePolicyManager.setApplicationRestrictions(EnforcerDeviceAdminReceiver.getComponentName(activity),
            Constants.PACKAGE_NAME_APP_RESTRICTION_SCHEMA, mCurrentRestrictions);
}

From source file:org.emergent.android.weave.PasswordListFragment.java

@Override
public void onListItemClick(ListView l, View v, int position, long id) {
    Activity activity = getActivity();
    if (activity == null) {
        Log.w(TAG, "onListItemClick: Activity was null!");
        return;/*from   ww  w.j  av  a2  s.co m*/
    }

    ListAdapter listAdapter = getListAdapter();

    Cursor cursor = (Cursor) listAdapter.getItem(position);
    String pword = cursor.getString(cursor.getColumnIndex(Passwords.Columns.PASSWORD));

    ClipboardManager clipboard = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE);
    clipboard.setText(pword);
    String msg = "Password copied to clipboard.";
    Toast toast = Toast.makeText(activity, msg, Toast.LENGTH_SHORT);
    toast.show();
}

From source file:com.example.android.apprestrictionenforcer.AppRestrictionEnforcerFragment.java

/**
 * Loads the restrictions for the AppRestrictionSchema sample.
 *
 * @param activity The activity//ww  w . j  a  va2 s  .c  om
 */
private void loadRestrictions(Activity activity) {
    RestrictionsManager manager = (RestrictionsManager) activity.getSystemService(Context.RESTRICTIONS_SERVICE);
    List<RestrictionEntry> restrictions = manager
            .getManifestRestrictions(Constants.PACKAGE_NAME_APP_RESTRICTION_SCHEMA);
    SharedPreferences prefs = activity.getSharedPreferences(PREFS_KEY, Context.MODE_PRIVATE);
    for (RestrictionEntry restriction : restrictions) {
        String key = restriction.getKey();
        if (RESTRICTION_KEY_SAY_HELLO.equals(key)) {
            updateCanSayHello(prefs.getBoolean(RESTRICTION_KEY_SAY_HELLO, restriction.getSelectedState()));
        } else if (RESTRICTION_KEY_MESSAGE.equals(key)) {
            updateMessage(prefs.getString(RESTRICTION_KEY_MESSAGE, restriction.getSelectedString()));
        } else if (RESTRICTION_KEY_NUMBER.equals(key)) {
            updateNumber(prefs.getInt(RESTRICTION_KEY_NUMBER, restriction.getIntValue()));
        } else if (RESTRICTION_KEY_RANK.equals(key)) {
            updateRank(activity, restriction.getChoiceValues(),
                    prefs.getString(RESTRICTION_KEY_RANK, restriction.getSelectedString()));
        } else if (RESTRICTION_KEY_APPROVALS.equals(key)) {
            updateApprovals(activity, restriction.getChoiceValues(),
                    TextUtils.split(
                            prefs.getString(RESTRICTION_KEY_APPROVALS,
                                    TextUtils.join(DELIMETER, restriction.getAllSelectedStrings())),
                            DELIMETER));
        } else if (BUNDLE_SUPPORTED && RESTRICTION_KEY_ITEMS.equals(key)) {
            String itemsString = prefs.getString(RESTRICTION_KEY_ITEMS, "");
            HashMap<String, String> items = new HashMap<>();
            for (String itemString : TextUtils.split(itemsString, DELIMETER)) {
                String[] strings = itemString.split(SEPARATOR, 2);
                items.put(strings[0], strings[1]);
            }
            updateItems(activity, items);
        }
    }
}

From source file:com.megster.cordova.ble.central.BLECentralPlugin.java

@Override
public boolean execute(String action, CordovaArgs args, CallbackContext callbackContext) throws JSONException {

    LOG.d(TAG, "action = " + action);

    if (bluetoothAdapter == null) {
        Activity activity = cordova.getActivity();
        BluetoothManager bluetoothManager = (BluetoothManager) activity
                .getSystemService(Context.BLUETOOTH_SERVICE);
        bluetoothAdapter = bluetoothManager.getAdapter();
    }//from  w w w . j  a  v a 2s. co  m

    boolean validAction = true;

    if (action.equals(SCAN)) {

        UUID[] serviceUUIDs = parseServiceUUIDList(args.getJSONArray(0));
        int scanSeconds = args.getInt(1);
        findLowEnergyDevices(callbackContext, serviceUUIDs, scanSeconds);

    } else if (action.equals(START_SCAN)) {

        UUID[] serviceUUIDs = parseServiceUUIDList(args.getJSONArray(0));
        findLowEnergyDevices(callbackContext, serviceUUIDs, -1);

    } else if (action.equals(STOP_SCAN)) {

        bluetoothAdapter.stopLeScan(this);
        callbackContext.success();

    } else if (action.equals(LIST)) {

        listKnownDevices(callbackContext);

    } else if (action.equals(CONNECT)) {

        String macAddress = args.getString(0);
        connect(callbackContext, macAddress);

    } else if (action.equals(DISCONNECT)) {

        String macAddress = args.getString(0);
        disconnect(callbackContext, macAddress);

    } else if (action.equals(READ)) {

        String macAddress = args.getString(0);
        UUID serviceUUID = uuidFromString(args.getString(1));
        UUID characteristicUUID = uuidFromString(args.getString(2));
        read(callbackContext, macAddress, serviceUUID, characteristicUUID);

    } else if (action.equals(WRITE)) {

        String macAddress = args.getString(0);
        UUID serviceUUID = uuidFromString(args.getString(1));
        UUID characteristicUUID = uuidFromString(args.getString(2));
        byte[] data = args.getArrayBuffer(3);
        int type = BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT;
        write(callbackContext, macAddress, serviceUUID, characteristicUUID, data, type);

    } else if (action.equals(WRITE_WITHOUT_RESPONSE)) {

        String macAddress = args.getString(0);
        UUID serviceUUID = uuidFromString(args.getString(1));
        UUID characteristicUUID = uuidFromString(args.getString(2));
        byte[] data = args.getArrayBuffer(3);
        int type = BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE;
        write(callbackContext, macAddress, serviceUUID, characteristicUUID, data, type);

    } else if (action.equals(START_NOTIFICATION)) {

        String macAddress = args.getString(0);
        UUID serviceUUID = uuidFromString(args.getString(1));
        UUID characteristicUUID = uuidFromString(args.getString(2));
        registerNotifyCallback(callbackContext, macAddress, serviceUUID, characteristicUUID);

    } else if (action.equals(STOP_NOTIFICATION)) {

        String macAddress = args.getString(0);
        UUID serviceUUID = uuidFromString(args.getString(1));
        UUID characteristicUUID = uuidFromString(args.getString(2));
        removeNotifyCallback(callbackContext, macAddress, serviceUUID, characteristicUUID);

    } else if (action.equals(IS_ENABLED)) {

        if (bluetoothAdapter.isEnabled()) {
            callbackContext.success();
        } else {
            callbackContext.error("Bluetooth is disabled.");
        }

    } else if (action.equals(IS_CONNECTED)) {

        String macAddress = args.getString(0);

        if (peripherals.containsKey(macAddress) && peripherals.get(macAddress).isConnected()) {
            callbackContext.success();
        } else {
            callbackContext.error("Not connected.");
        }

    } else if (action.equals(SETTINGS)) {

        Intent intent = new Intent(Settings.ACTION_BLUETOOTH_SETTINGS);
        cordova.getActivity().startActivity(intent);
        callbackContext.success();

    } else if (action.equals(ENABLE)) {

        enableBluetoothCallback = callbackContext;
        Intent intent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
        cordova.startActivityForResult(this, intent, REQUEST_ENABLE_BLUETOOTH);

    } else {

        validAction = false;

    }

    return validAction;
}

From source file:com.feathercoin.wallet.feathercoin.ui.SendingAddressesFragment.java

@Override
public void onAttach(final Activity activity) {
    super.onAttach(activity);

    this.activity = (AbstractWalletActivity) activity;
    // This works for both clipboard managers because android.content.ClipboardManager is subclassed from the old one.
    this.clipboardManager = (android.text.ClipboardManager) activity
            .getSystemService(Context.CLIPBOARD_SERVICE);
    this.loaderManager = getLoaderManager();
}

From source file:com.android.yijiang.kzx.widget.betterpickers.calendardatepicker.CalendarDatePickerDialog.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    final Activity activity = getActivity();
    activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
    mVibrator = (Vibrator) activity.getSystemService(Context.VIBRATOR_SERVICE);
    if (savedInstanceState != null) {
        mCalendar.set(Calendar.YEAR, savedInstanceState.getInt(KEY_SELECTED_YEAR));
        mCalendar.set(Calendar.MONTH, savedInstanceState.getInt(KEY_SELECTED_MONTH));
        mCalendar.set(Calendar.DAY_OF_MONTH, savedInstanceState.getInt(KEY_SELECTED_DAY));
    }//from  ww w .ja  v a  2s  .  co  m
}

From source file:com.moodmap.SplashScreenActivity.java

public boolean networkStatus(Activity context) {
    boolean status = false;
    int i = 0;//from w w w  .  j  a  v  a  2  s.  c om
    try {
        String service = Context.CONNECTIVITY_SERVICE;
        ConnectivityManager connectivity = (ConnectivityManager) context.getSystemService(service);
        connectivity.setNetworkPreference(1);

        NetworkInfo networkInfo[] = connectivity.getAllNetworkInfo();
        int cnt = networkInfo.length;

        for (i = 0; i < cnt; i++) {

            if (networkInfo[i].isConnected() == true) {
                status = true;
                Log.v("Network Provider", "" + networkInfo[i].getTypeName());
            }
        }
    } catch (Exception ee) {
        ee.printStackTrace();
    }
    Log.v("networkStatus", "##########" + status);
    return status;
}

From source file:com.supremainc.biostar2.base.BaseListAdapter.java

public BaseListAdapter(Activity context, ArrayList<T> items, ListView listView, Popup popup) {
    this.mItems = items;
    mContext = context;/*from   www . j  a  va2  s  . c om*/
    mListView = listView;
    mListView.setOnItemClickListener(this);
    mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    mToastPopup = new ToastPopup(context);
    mPopup = popup;
}

From source file:mirko.android.datetimepicker.date.DatePickerDialogSupport.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    final Activity activity = getActivity();
    activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
    mVibrator = (Vibrator) activity.getSystemService(Context.VIBRATOR_SERVICE);
    if (savedInstanceState != null) {
        mCalendar.set(Calendar.YEAR, savedInstanceState.getInt(KEY_SELECTED_YEAR));
        mCalendar.set(Calendar.MONTH, savedInstanceState.getInt(KEY_SELECTED_MONTH));
        mCalendar.set(Calendar.DAY_OF_MONTH, savedInstanceState.getInt(KEY_SELECTED_DAY));
        mEnableClearButton = savedInstanceState.getBoolean(KEY_ENABLE_CLEAR_BUTTON, false);
    }// w w w.  j  a v a  2 s.c  o  m
}