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:org.safegees.safegees.gui.view.MainActivity.java

@TargetApi(Build.VERSION_CODES.M)
private void checkPermissions() {
    List<String> permissions = new ArrayList<>();
    String message = "OSMDroid permissions:";
    if (ContextCompat.checkSelfPermission(this,
            Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        permissions.add(Manifest.permission.ACCESS_FINE_LOCATION);
        message += "\nStorage access to store map tiles.";
    }/*  w w  w  .ja  v  a  2  s .  co m*/
    if (ContextCompat.checkSelfPermission(this,
            Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
        permissions.add(Manifest.permission.WRITE_EXTERNAL_STORAGE);
        message += "\nLocation to show user location.";
    }
    if (!permissions.isEmpty()) {
        //Toast.makeText(this, message, Toast.LENGTH_LONG).show();
        String[] params = permissions.toArray(new String[permissions.size()]);
        requestPermissions(params, REQUEST_CODE_ASK_MULTIPLE_PERMISSIONS);
    } else {
        startAfterPermissions();

    }
}

From source file:com.microsoft.azure.engagement.cordova.AZME.java

public void onRequestPermissionResult(int requestCode, String[] permissions, int[] grantResults)
        throws JSONException {

    if (requestCode == 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED)
        EngagementShared.instance().refreshPermissions();
}

From source file:co.tinode.tindroid.ContactsFragment.java

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
        @NonNull int[] grantResults) {
    if (requestCode == PERMISSIONS_REQUEST_READ_CONTACTS) {
        if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
            // Permission is granted
            assignAdapter();/* ww  w.  j  a va2  s . c  om*/
        } else {
            ((TextView) getActivity().findViewById(android.R.id.empty))
                    .setText(R.string.contacts_permission_denied);
        }
    }
}

From source file:co.taqat.call.assistant.AssistantActivity.java

public void checkAndRequestPermission(String permission, int result) {
    int permissionGranted = getPackageManager().checkPermission(permission, getPackageName());
    Log.i("[Permission] " + permission + " is "
            + (permissionGranted == PackageManager.PERMISSION_GRANTED ? "granted" : "denied"));

    if (permissionGranted != PackageManager.PERMISSION_GRANTED) {
        if (LinphonePreferences.instance().firstTimeAskingForPermission(permission)
                || ActivityCompat.shouldShowRequestPermissionRationale(this, permission)) {
            Log.i("[Permission] Asking for " + permission);
            ActivityCompat.requestPermissions(this, new String[] { permission }, result);
        }/*from   w  w w.  ja  va 2 s  .  c o  m*/
    }
}

From source file:cc.metapro.openct.myclass.ClassActivity.java

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
        @NonNull int[] grantResults) {
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    if (requestCode == REQUEST_WRITE_STORAGE) {
        if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
            showFilerChooser();/*from   w w  w .j a v  a2  s.  c  om*/
        } else {
            Toast.makeText(this, R.string.no_write_permission, Toast.LENGTH_LONG).show();
        }
    }
}

From source file:ota.otaupdates.MainActivity.java

private boolean checkPermission() {
    int result = ContextCompat.checkSelfPermission(MainActivity.this,
            android.Manifest.permission.WRITE_EXTERNAL_STORAGE);
    return result == PackageManager.PERMISSION_GRANTED;
}

From source file:io.selendroid.server.ServerInstrumentation.java

public void addCallLog(CallLogEntry log) throws PermissionDeniedException {
    String permission = Manifest.permission.WRITE_CALL_LOG;
    if (getTargetContext().checkCallingOrSelfPermission(permission) == PackageManager.PERMISSION_GRANTED) {
        ContentValues values = new ContentValues();
        values.put(CallLog.Calls.CACHED_NUMBER_TYPE, 0);
        values.put(CallLog.Calls.TYPE, log.getDirection());
        values.put(CallLog.Calls.DATE, log.getDate().getTime());
        values.put(CallLog.Calls.DURATION, log.getDuration());
        values.put(CallLog.Calls.NUMBER, log.getNumber());
        getTargetContext().getContentResolver().insert(CallLog.Calls.CONTENT_URI, values);
    } else {//w  w  w . j ava2  s  . co m
        throw new PermissionDeniedException(
                "Application Under Test does not have the required WRITE_CALL_LOGS permission for this feature..");
    }
}

From source file:io.kristal.locationplugin.LocationPlugin.java

@Override
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
    switch (requestCode) {
    case LOCATION_PERMISSION_REQUEST:
        onRequestLocationPermissionResult(grantResults[0] == PackageManager.PERMISSION_GRANTED);
    default://w w  w .j av a 2 s .c  o m
        break;
    }
}

From source file:co.taqat.call.CallIncomingActivity.java

@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
    for (int i = 0; i < permissions.length; i++) {
        Log.i("[Permission] " + permissions[i] + " is "
                + (grantResults[i] == PackageManager.PERMISSION_GRANTED ? "granted" : "denied"));
    }/*from  w w w  . j  a v a  2s. c om*/
}

From source file:chinanurse.cn.nurse.Fragment_Nurse_job.IdentityFragment_ACTIVITY.java

private void getCheck() {
    if (ContextCompat.checkSelfPermission(activity,
            Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
        //WRITE_EXTERNAL_STORAGE??
        ActivityCompat.requestPermissions(activity, new String[] { Manifest.permission.CAMERA }, 100);
    }// www .  j ava2 s . co  m
    if (ContextCompat.checkSelfPermission(activity,
            Manifest.permission.RECEIVE_BOOT_COMPLETED) != PackageManager.PERMISSION_GRANTED) {
        //WRITE_EXTERNAL_STORAGE??
        ActivityCompat.requestPermissions(activity, new String[] { Manifest.permission.RECEIVE_BOOT_COMPLETED },
                100);
    }
    if (ContextCompat.checkSelfPermission(activity,
            Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {
        //WRITE_EXTERNAL_STORAGE??
        ActivityCompat.requestPermissions(activity, new String[] { Manifest.permission.READ_PHONE_STATE }, 100);
    }
    if (ContextCompat.checkSelfPermission(activity,
            Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
        //WRITE_EXTERNAL_STORAGE??
        ActivityCompat.requestPermissions(activity, new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE },
                100);
    }
    if (ContextCompat.checkSelfPermission(activity,
            Manifest.permission.MOUNT_UNMOUNT_FILESYSTEMS) != PackageManager.PERMISSION_GRANTED) {
        //WRITE_EXTERNAL_STORAGE??
        ActivityCompat.requestPermissions(activity,
                new String[] { Manifest.permission.MOUNT_UNMOUNT_FILESYSTEMS }, 100);
    }
}