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:com.metinkale.prayerapp.utils.PermissionUtils.java

public void needNotificationPolicy(final Activity act) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
        return;/*from   w  w  w  .  j a v  a2 s  .  c o m*/
    }
    NotificationManager nm = (NotificationManager) act.getSystemService(Context.NOTIFICATION_SERVICE);
    pNotPolicy = nm.isNotificationPolicyAccessGranted();
    if (!pNotPolicy) {
        Intent intent = new Intent(android.provider.Settings.ACTION_NOTIFICATION_POLICY_ACCESS_SETTINGS);

        PackageManager packageManager = act.getPackageManager();
        if (intent.resolveActivity(packageManager) != null) {
            act.startActivity(intent);
        } else {
            ActivityCompat.requestPermissions(act,
                    new String[] { Manifest.permission.ACCESS_NOTIFICATION_POLICY }, 0);
        }
    }
}

From source file:de.grobox.liberario.ui.LocationInputGPSView.java

public LocationInputGPSView(Activity context, LocationInputViewHolder ui, int caller) {
    super(context, ui, false);

    this.caller = caller;
    this.locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);

    locAdapter.setGPS(true);/*from w w  w  .j av  a2  s .co m*/
}

From source file:com.android.contacts.common.vcard.NotificationImportExportListener.java

public NotificationImportExportListener(Activity activity) {
    mContext = activity;/*from  w ww. j ava2s  .c  o m*/
    mNotificationManager = (NotificationManager) activity.getSystemService(Context.NOTIFICATION_SERVICE);
    mHandler = new Handler(this);
}

From source file:com.ceino.chaperonandroid.activities.LicenseActivity.java

private void hideSoftKeyboard(Activity activity) {
    InputMethodManager inputMethodManager = (InputMethodManager) activity
            .getSystemService(Activity.INPUT_METHOD_SERVICE);
    inputMethodManager.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), 0);
}

From source file:org.pixmob.feedme.ui.EntriesFragment.java

private void authenticateAccount(String accountName) {
    Log.i(TAG, "Authenticating account: " + accountName);

    final Activity a = getActivity();
    final AccountManager am = (AccountManager) a.getSystemService(Context.ACCOUNT_SERVICE);
    final Account account = new Account(accountName, GOOGLE_ACCOUNT);
    am.getAuthToken(account, "reader", null, a, new AccountManagerCallback<Bundle>() {
        @Override//from  w  ww  . jav  a 2  s . co m
        public void run(AccountManagerFuture<Bundle> resultContainer) {
            String authToken = null;
            final Bundle result;
            try {
                result = resultContainer.getResult();
                authToken = result.getString(AccountManager.KEY_AUTHTOKEN);
            } catch (IOException e) {
                Log.w(TAG, "I/O error while authenticating account " + account.name, e);
            } catch (OperationCanceledException e) {
                Log.w(TAG, "Authentication was canceled for account " + account.name, e);
            } catch (AuthenticatorException e) {
                Log.w(TAG, "Authentication failed for account " + account.name, e);
            }

            if (authToken == null) {
                Toast.makeText(a, a.getString(R.string.authentication_failed), Toast.LENGTH_SHORT).show();
            } else {
                Log.i(TAG, "Authentication done");
                onAuthenticationDone(account.name, authToken);
            }
        }
    }, null);
}

From source file:com.app.sample.chatting.widget.KJChatKeyboard.java

/**
 * ??//from ww w . j a v  a 2  s  .c  o  m
 */
public void hideKeyboard(Context context) {
    Activity activity = (Activity) context;
    if (activity != null) {
        InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
        if (imm.isActive() && activity.getCurrentFocus() != null) {
            imm.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), 0);
        }
    }
}

From source file:mobisocial.musubi.social.QRInviteDialog.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    Activity context = getActivity();
    getDialog().setTitle("Exchange Info");
    // This assumes the view is full screen, which is a bad assumption
    WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = manager.getDefaultDisplay();
    int width = display.getWidth();
    int height = display.getHeight();
    int smallerDimension = width < height ? width : height;

    Uri uri = EmailInviteActivity.getInvitationUrl(context);
    if (uri.getQueryParameter("n") == null) {
        Toast.makeText(getActivity(), "You must set up an account and a enter a name to connect with friends.",
                Toast.LENGTH_LONG).show();
        dismiss();/*from   ww  w  . j  av a  2  s.co m*/
        return;
    }
    if (uri.getQueryParameter("t") == null) {
        dismiss();
        Toast.makeText(getActivity(), "No identities to share", Toast.LENGTH_SHORT).show();
        return;
    }
    Intent intent = new Intent(Intents.Encode.ACTION);
    intent.setClass(getActivity(), QRInviteDialog.class);
    intent.putExtra(Intents.Encode.TYPE, Contents.Type.TEXT);
    intent.putExtra(Intents.Encode.DATA, uri.toString());

    try {
        qrCodeEncoder = new QRCodeEncoder(context, intent, smallerDimension);
        //setTitle(getString(R.string.app_name) + " - " + qrCodeEncoder.getTitle());
        Bitmap bitmap = qrCodeEncoder.encodeAsBitmap();
        ImageView image = (ImageView) view.findViewById(R.id.image_view);
        image.setImageBitmap(bitmap);
        TextView contents = (TextView) view.findViewById(R.id.contents_text_view);
        contents.setText(qrCodeEncoder.getDisplayContents());
        view.findViewById(R.id.ok_button).setOnClickListener(mCameraListener);
    } catch (WriterException e) {
        Log.e(TAG, "Could not encode barcode", e);
        showErrorMessage(R.string.msg_encode_contents_failed);
        qrCodeEncoder = null;
    } catch (IllegalArgumentException e) {
        Log.e(TAG, "Could not encode barcode", e);
        showErrorMessage(R.string.msg_encode_contents_failed);
        qrCodeEncoder = null;
    }
}

From source file:me.ziccard.secureit.async.upload.AuthenticatorTask.java

public AuthenticatorTask(Activity activity, String username, String password) {
    this.activity = activity;
    this.username = username;
    this.password = password;
    this.manager = (TelephonyManager) activity.getSystemService(Context.TELEPHONY_SERVICE);
}

From source file:com.megster.cordova.rfduino.RFduinoPlugin.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  .ja  v  a2  s. c  om*/

    boolean validAction = true;

    if (action.equals(DISCOVER)) {

        int scanSeconds = args.getInt(0);
        findLowEnergyDevices(callbackContext, scanSeconds);

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

        listKnownDevices(callbackContext);

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

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

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

        registerOnDataCallback(callbackContext);

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

        disconnect(callbackContext);

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

        byte[] data = args.getArrayBuffer(0);
        write(callbackContext, data);

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

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

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

        if (activePeripheral != null && activePeripheral.isConnected()) {
            callbackContext.success();
        } else {
            callbackContext.error("Not connected.");
        }

    } else {

        validAction = false;

    }

    return validAction;
}

From source file:cc.mintcoin.wallet.ui.WalletAddressFragment.java

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

    this.activity = (FragmentActivity) activity;
    this.application = (WalletApplication) activity.getApplication();
    this.config = application.getConfiguration();
    this.nfcManager = (NfcManager) activity.getSystemService(Context.NFC_SERVICE);
}