Example usage for android.content.pm PackageManager PERMISSION_GRANTED

List of usage examples for android.content.pm PackageManager PERMISSION_GRANTED

Introduction

In this page you can find the example usage for android.content.pm PackageManager PERMISSION_GRANTED.

Prototype

int PERMISSION_GRANTED

To view the source code for android.content.pm PackageManager PERMISSION_GRANTED.

Click Source Link

Document

Permission check result: this is returned by #checkPermission if the permission has been granted to the given package.

Usage

From source file:com.platform.GeoLocationManager.java

public void startGeoSocket(Session sess) {
    session = sess;//  w w  w .  jav a  2 s  . c  o m

    final MainActivity app = MainActivity.app;
    if (app == null)
        return;
    final LocationManager locationManager = (LocationManager) app.getSystemService(Context.LOCATION_SERVICE);

    app.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            if (ActivityCompat.checkSelfPermission(app,
                    Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
                    && ActivityCompat.checkSelfPermission(app,
                            Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
                RuntimeException ex = new RuntimeException("startGeoSocket, can't happen");
                Log.e(TAG, "run: startGeoSocket, can't happen");
                FirebaseCrash.report(ex);
                return;
            }
            locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 1000, 0,
                    socketLocationListener);
            locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 0,
                    socketLocationListener);

        }
    });
}

From source file:com.aitorvs.android.eyetoggle.MainActivity.java

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
        @NonNull int[] grantResults) {
    if (requestCode != REQUEST_CAMERA_PERM) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        return;/* www.j a va  2s .co  m*/
    }

    if (grantResults.length != 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
        createCameraResources();
        return;
    }

    DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            finish();
        }
    };

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle("EyeControl").setMessage("No camera permission").setPositiveButton("Ok", listener).show();
}

From source file:com.amti.vela.bluetoothlegatt.bluetooth.DeviceScanActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_device_search);

    //have to request location permissions for marshmallow to do bluetooth
    if (Build.VERSION.SDK_INT >= 23) {
        if (checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
                && checkSelfPermission(
                        Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
            requestPermissions(new String[] { Manifest.permission.ACCESS_FINE_LOCATION,
                    Manifest.permission.ACCESS_COARSE_LOCATION }, 1);

        } else {//from   w  ww.j  ava 2  s  .  c o m

        }
    }

    initGui();

    btInit();

    autoConnectIfEnabled();
}

From source file:io.v.syncslides.SignInActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_sign_in);
    mPrefs = PreferenceManager.getDefaultSharedPreferences(this);
    mAccountName = mPrefs.getString(SignInActivity.PREF_USER_ACCOUNT_NAME, "");
    mProgressDialog = new ProgressDialog(this);
    if (mAccountName.isEmpty()) {
        mProgressDialog.setMessage("Signing in...");
        mProgressDialog.show();//from www  .jav a 2  s  . co  m
        if (checkSelfPermission(Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED) {
            requestPermissions(new String[] { Manifest.permission.READ_CONTACTS },
                    REQUEST_CODE_ASK_PERMISSIONS);
            return;
        }
        pickAccount();
    } else {
        finishActivity();
    }
}

From source file:au.com.domain.AccountsAutoCompleteTextView.java

private boolean isPermissionGranted() {
    return ContextCompat.checkSelfPermission(getContext(),
            Manifest.permission.GET_ACCOUNTS) == PackageManager.PERMISSION_GRANTED;
}

From source file:com.futurologeek.smartcrossing.crop.CropImageActivity.java

@Override
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
    switch (requestCode) {
    case 69: {/* w  w w  .  j a v a2s  .  co  m*/
        // If request is cancelled, the result arrays are empty.
        if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {

            setAll();

        } else {

            requestWritePermission();
        }
        return;
    }

    }
}

From source file:br.com.anteros.vendas.gui.ManutencaoTabelasActivity.java

private void compartilharBancoDados() {
    new QuestionAlert(this, "Manuteno Tabelas", "Deseja compartilhar o banco de dados ?",
            new QuestionAlert.QuestionListener() {

                public void onPositiveClick() {
                    if (ActivityCompat.checkSelfPermission(ManutencaoTabelasActivity.this,
                            Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED
                            || ActivityCompat.checkSelfPermission(ManutencaoTabelasActivity.this,
                                    Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
                        ActivityCompat// www . j  av a 2  s  . c  o m
                                .requestPermissions(ManutencaoTabelasActivity.this,
                                        new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE,
                                                Manifest.permission.READ_EXTERNAL_STORAGE },
                                        REQUEST_PERMISSION_SHARE);
                    } else {
                        selecionarArquivoCompartilhar();
                    }
                }

                public void onNegativeClick() {
                }
            }).show();
}

From source file:com.alibaba.weex.extend.module.WXEventModule.java

@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    if (requestCode == CAMERA_PERMISSION_REQUEST_CODE && grantResults.length > 0
            && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
        mWXSDKInstance.getContext()/*  w w  w. jav a2 s .c  o m*/
                .startActivity(new Intent(mWXSDKInstance.getContext(), CaptureActivity.class));
    }
}

From source file:am.project.x.business.widgets.zxingscanview.ZxingScanViewActivity.java

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
        @NonNull int[] grantResults) {
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    switch (requestCode) {
    case PERMISSIONS_REQUEST_CAMERA: {
        if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
            mVScan.open();//from   w ww .  j av a 2  s  .  co  m
        } else {
            mVForeground.setMode(ZxingForegroundView.MODE_ERROR);
        }
    }
    }
}

From source file:ch.ethz.inf.vs.a1.fabischn.ble.MainActivity.java

public boolean checkLocationPermission() {
    String permission = "android.permission.ACCESS_FINE_LOCATION";
    int res = this.checkCallingOrSelfPermission(permission);
    return (res == PackageManager.PERMISSION_GRANTED);
}