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:at.ac.tuwien.caa.docscan.ui.StartActivity.java

@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
    if (requestCode == PERMISSION_CAMERA) {
        // Request for camera permission.
        if (grantResults.length == 1 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
            // Permission has been granted. Start camera preview Activity.
            Snackbar.make(mLayout, "Camera permission was granted. Starting preview.", Snackbar.LENGTH_SHORT)
                    .show();//from  w ww  .j av a  2s  .  c  o m
            startCamera();
        } else {
            // Permission request was denied.
            Snackbar.make(mLayout, "Camera permission request was denied.", Snackbar.LENGTH_SHORT).show();
        }
    }
    // END_INCLUDE(onRequestPermissionsResult)
}

From source file:com.andremion.louvre.StoragePermissionActivity.java

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[],
        @NonNull int[] grantResults) {
    switch (requestCode) {
    case REQUEST_READ_EXTERNAL_STORAGE: {
        // If request is cancelled, the result arrays are empty.
        if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
            onPermissionGranted();/*from   www  . j  a  v a 2 s . com*/
        } else {
            showExplanation();
        }
        break;
    }
    default:
    }
}

From source file:cn.nekocode.camerafilter.MainActivity.java

@Override
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
    switch (requestCode) {
    case REQUEST_CAMERA_PERMISSION: {
        if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
            setupCameraPreviewView();//  w  ww.j  a  v a 2 s.  co m
        }
    }
    }
}

From source file:jp.seikeidenron.androidtv.common.Utils.java

public static boolean hasPermission(final Context context, final String permission) {
    return PackageManager.PERMISSION_GRANTED == context.getPackageManager().checkPermission(permission,
            context.getPackageName());//from w ww.  j  a  va  2 s.  c  om
}

From source file:io.github.carlorodriguez.alarmon.AlarmClockService.java

@Override
public void onCreate() {
    super.onCreate();
    // Registers an exception handler of capable of writing the stack trace
    // to the device's SD card.  This is only possible if the proper
    // permissions are available.
    if (getPackageManager().checkPermission("android.permission.WRITE_EXTERNAL_STORAGE",
            getPackageName()) == PackageManager.PERMISSION_GRANTED) {
        Thread.setDefaultUncaughtExceptionHandler(
                new LoggingUncaughtExceptionHandler(Environment.getExternalStorageDirectory().getPath()));
    }/*from  w ww. j  a  v  a 2s .  c o m*/

    // Access to in-memory and persistent data structures.
    db = new DbAccessor(getApplicationContext());
    pendingAlarms = new PendingAlarmList(getApplicationContext());

    // Schedule enabled alarms during initial startup.
    for (Long alarmId : db.getEnabledAlarms()) {
        if (pendingAlarms.pendingTime(alarmId) != null) {
            continue;
        }
        if (AppSettings.isDebugMode(getApplicationContext())) {
            Toast.makeText(getApplicationContext(), "RENABLE " + alarmId, Toast.LENGTH_SHORT).show();
        }

        AlarmTime alarmTime = null;

        AlarmInfo info = db.readAlarmInfo(alarmId);

        if (info != null) {
            alarmTime = info.getTime();
        }

        pendingAlarms.put(alarmId, alarmTime);
    }

    ReceiverNotificationRefresh.startRefreshing(getApplicationContext());
}

From source file:com.onesignal.TrackGooglePurchase.java

static boolean CanTrack(Context context) {
    if (iapEnabled == -99)
        iapEnabled = context.checkCallingOrSelfPermission("com.android.vending.BILLING");
    try {/*from w w w .j ava  2 s  .  c  o  m*/
        if (iapEnabled == PackageManager.PERMISSION_GRANTED)
            IInAppBillingServiceClass = Class.forName("com.android.vending.billing.IInAppBillingService");
    } catch (Throwable t) {
        iapEnabled = 0;
        return false;
    }

    return (iapEnabled == PackageManager.PERMISSION_GRANTED);
}

From source file:ca.ualberta.cs.drivr.GPSTracker.java

/**
 * Gets the User Current Location through GPS or Wifi
 * @return returns user current Location.
 *//*ww w . ja  va2  s.co m*/
public Location getLocation() {
    try {
        locationManger = (LocationManager) mContext.getSystemService(Context.LOCATION_SERVICE);

        // Check that App can get Location
        isGPSEnabled = locationManger.isProviderEnabled(LocationManager.GPS_PROVIDER);
        isNetworkEnabled = locationManger.isProviderEnabled(LocationManager.NETWORK_PROVIDER);

        if (!isGPSEnabled && !isNetworkEnabled) {
            // Services not Enabled
            enableGPS();
        } else {
            this.canGetLocation = true;
            if (isNetworkEnabled) {
                location = null;
                if (ActivityCompat.checkSelfPermission(mContext,
                        Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED
                        && ActivityCompat.checkSelfPermission(mContext,
                                Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
                    locationManger.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 1, 1, this);
                    if (locationManger != null) {
                        location = locationManger.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);

                        if (location != null) {
                            myLatitude = location.getLatitude();
                            myLongitude = location.getLongitude();
                        }
                    }

                }
            }
            if (isGPSEnabled) {
                location = null;
                if (ActivityCompat.checkSelfPermission(mContext,
                        Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED
                        && ActivityCompat.checkSelfPermission(mContext,
                                Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
                    locationManger.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1, 1, this);
                    if (locationManger != null) {
                        location = locationManger.getLastKnownLocation(LocationManager.GPS_PROVIDER);

                        if (location != null) {
                            myLatitude = location.getLatitude();
                            myLongitude = location.getLongitude();
                        }
                    }

                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    if (myLocation != null) {
        return myLocation;
    } else {
        // Android Emulator Can't Use Wifi
        myLocation = new Location("Edmonton");
        myLocation.setLatitude(53.5232);
        myLocation.setLongitude(-113.5263);
        myLatitude = myLocation.getLatitude();
        myLongitude = myLocation.getLongitude();

        return myLocation;
    }
}

From source file:tk.android.client.activity.Activity_client.java

private void init() {
    core = new Twitter_core(activity);
    button_version = (Button) activity.findViewById(R.id.button_version);
    progressBar = (ProgressBar) activity.findViewById(R.id.progressBar);
    textView_version = (TextView) activity.findViewById(R.id.textView_version);

    activity.findViewById(R.id.layout_support).setOnClickListener(this);
    activity.findViewById(R.id.layout_pro).setOnClickListener(this);
    activity.findViewById(R.id.layout_license).setOnClickListener(this);
    button_version.setOnClickListener(this);
    button_version.setClickable(false);//from   ww w  . ja  v a2 s .c  o m

    try {
        PackageInfo info = getPackageManager().getPackageInfo(getPackageName(),
                PackageManager.PERMISSION_GRANTED);
        current_version = info.versionName;
        textView_version.setText("Version " + current_version);
    } catch (Exception e) {
        e.printStackTrace();
        textView_version.setText("Version Error");
    }

    new Thread(new Runnable() {

        @Override
        public void run() {
            HttpClient httpClient = new DefaultHttpClient();
            HttpGet get = new HttpGet(PLAY_STORE_URL);
            HttpResponse res = null;
            try {
                res = httpClient.execute(get);
            } catch (IOException e) {
                e.printStackTrace();
                new UiHandler() {

                    @Override
                    public void run() {
                        progressBar.setVisibility(View.GONE);
                        button_version.setText(R.string.something_is_wrong);
                        button_version.setClickable(false);
                    }

                }.post();
                return;
            }

            try {
                String source = EntityUtils.toString(res.getEntity());
                Pattern p1 = Pattern
                        .compile("<div class=\"content\" itemprop=\"softwareVersion\"> [0-9.]+  </div>");
                Matcher m1 = p1.matcher(source);
                if (!m1.find()) {
                    Log.d("", "software version not found.");
                    return;
                }
                Pattern p2 = Pattern.compile("[0-9.]+");
                Matcher m2 = p2.matcher(m1.group());
                if (!m2.find()) {
                    Log.d("", "software version not found.");
                    return;
                }
                final String newest_version = m2.group();

                new UiHandler() {

                    @Override
                    public void run() {
                        progressBar.setVisibility(View.GONE);
                        button_version.setText(newest_version.equals(current_version) ? R.string.newest_version
                                : R.string.there_is_update);
                        button_version.setClickable(!newest_version.equals(current_version));
                    }

                }.post();

            } catch (Exception e) {
                e.printStackTrace();
                new UiHandler() {

                    @Override
                    public void run() {
                        progressBar.setVisibility(View.GONE);
                        button_version.setText(R.string.something_is_wrong);
                        button_version.setClickable(false);
                    }

                }.post();
            }
        }

    }).start();
}

From source file:arun.com.chameleonskinforkwlp.activities.CameraCapturerActivity.java

/**
 * This is the API method which will initiate the camera picture taking process.
 *//*from   w  w w.  jav  a2 s  .c o  m*/
protected void checkPermissionAndLaunchCamera() {
    int permissionCheck = ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA);
    if (permissionCheck == PackageManager.PERMISSION_GRANTED) {
        launchCamera();
    } else {
        if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.CAMERA)) {
            onRequiredCameraPermissionRationale();
        } else {
            ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.CAMERA },
                    REQUEST_CAMERA_PERMISSION);
        }
    }
}

From source file:com.example.carrie.carrie_test1.scandrug.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_scandrug);
    cameraView = (SurfaceView) findViewById(R.id.cameraView);
    cameraView.setZOrderMediaOverlay(true);
    holder = cameraView.getHolder();//from ww w . j  av  a  2s .com
    barcode = new BarcodeDetector.Builder(this).setBarcodeFormats(Barcode.QR_CODE).build();
    if (!barcode.isOperational()) {
        Toast.makeText(getApplicationContext(), "Sorry ,Couldn't set up the detector", Toast.LENGTH_LONG)
                .show();
        this.finish();
    }

    cameraSource = new CameraSource.Builder(this, barcode).setFacing(CameraSource.CAMERA_FACING_BACK)
            .setRequestedFps(24).setAutoFocusEnabled(true).setRequestedPreviewSize(1920, 1024).build();
    cameraView.getHolder().addCallback(new SurfaceHolder.Callback() {
        @Override
        public void surfaceCreated(SurfaceHolder holder) {
            try {
                if (ContextCompat.checkSelfPermission(scandrug.this,
                        android.Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED) {
                    cameraSource.start(cameraView.getHolder());
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        @Override
        public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {

        }

        @Override
        public void surfaceDestroyed(SurfaceHolder holder) {

        }
    });
    barcode.setProcessor(new Detector.Processor<Barcode>() {
        @Override
        public void release() {

        }

        @Override
        public void receiveDetections(Detector.Detections<Barcode> detections) {
            final SparseArray<Barcode> barcodes = detections.getDetectedItems();
            if (barcodes.size() > 0) {
                int count;
                Intent intent = new Intent();
                intent.putExtra("barcode", barcodes.valueAt(0));
                Log.d("code", barcodes.valueAt(0).displayValue);
                urlcode = barcodes.valueAt(0).displayValue;
                Log.d("code2", barcodes.valueAt(0).displayValue);
                geturl();
                setResult(RESULT_OK, intent);
                //                    cameraSource.stop();
                //                    addNormalDialogEvent();

            }
        }
    });

}