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:ca.ualberta.cs.drivr.MainActivity.java

@Override
public void onMapReady(GoogleMap googleMap) {
    mMap = googleMap;/*from  w  w w  .j  a v a2  s . c om*/
    final MapController mapController = new MapController(mMap, context);

    if (ActivityCompat.checkSelfPermission(this,
            Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED
            && ActivityCompat.checkSelfPermission(this,
                    Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
        mMap.setMyLocationEnabled(true);
    }

    mMap.setOnMapClickListener(new GoogleMap.OnMapClickListener() {
        @Override
        public void onMapClick(LatLng latLng) {

            if (userManager.getUserMode() == UserMode.RIDER) {
                mapController.addPendingRequest(latLng, MainActivity.this);
            } else {
                ConcretePlace place = mapController.markerGeocodePlace(latLng);
                Gson gson = new GsonBuilder().registerTypeAdapter(Uri.class, new UriSerializer()).create();

                Intent intent = new Intent(MainActivity.this, SearchRequestActivity.class);
                String concretePlaceJson = gson.toJson(place);
                intent.putExtra(SearchRequestActivity.EXTRA_PLACE, concretePlaceJson);
                intent.putExtra(SearchRequestActivity.EXTRA_KEYWORD, "");
                Log.i(TAG, "Place: " + place.getName() + ", :" + place.getLatLng());
                startActivity(intent);

            }
        }
    });

    mMap.setOnMarkerDragListener(new GoogleMap.OnMarkerDragListener() {
        @Override
        public void onMarkerDragStart(Marker marker) {
        }

        @Override
        public void onMarkerDrag(Marker marker) {
            mMap.animateCamera(CameraUpdateFactory.newLatLng(marker.getPosition()));
        }

        @Override
        public void onMarkerDragEnd(Marker marker) {
        }
    });
}

From source file:camera2basic.Camera2BasicFragment.java

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
        @NonNull int[] grantResults) {
    if (requestCode == REQUEST_CAMERA_PERMISSION) {
        if (grantResults.length != 1 || grantResults[0] != PackageManager.PERMISSION_GRANTED) {
            ErrorDialog.newInstance(getString(R.string.request_permission)).show(getChildFragmentManager(),
                    FRAGMENT_DIALOG);/*  ww  w  .  ja va2s  . co m*/
        }
    } else {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    }
}

From source file:appteam.nith.hillffair.activities.HomeActivity.java

@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
    if (requestCode == PERMISSIONS_REQUEST_PHONE_CALL) {
        if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
            // Permission is granted
            call(a);/*from www  . j  a  v a 2  s  .  c o m*/
        } else {
            Toast.makeText(this, "Sorry!!! Permission Denied", Toast.LENGTH_SHORT).show();
        }
    }
}

From source file:at.ac.tuwien.caa.docscan.ui.CameraActivity.java

/**
 * Request to read the external storage. This method is used to enable file saving in Android >= marshmallow
 * (Android 6), since in this version external file opening is not allowed without user permission.
 *//*  www  .  j  a  va  2  s  .co  m*/
@TargetApi(16)
private void requestFileOpen() {

    // Check permission

    if (ActivityCompat.checkSelfPermission(this,
            Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
        // ask for permission:
        ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.READ_EXTERNAL_STORAGE },
                PERMISSION_READ_EXTERNAL_STORAGE);
    } else
        startScan();

}

From source file:bupt.tiantian.callrecorder.callrecorder.MainActivity.java

public void checkPermissions() {
    permissionReadContacts = ActivityCompat.checkSelfPermission(this,
            Manifest.permission.READ_CONTACTS) == PackageManager.PERMISSION_GRANTED;
    permissionWriteExternal = ActivityCompat.checkSelfPermission(this,
            Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED;

    if (!permissionReadContacts)
        if (ActivityCompat.checkSelfPermission(this,
                Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED) {

            // Should we show an explanation?
            if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.READ_CONTACTS)) {

                // Show an expanation to the user *asynchronously* -- don't block
                // this thread waiting for the user's response! After the user
                // sees the explanation, try again to request the permission.
                new android.app.AlertDialog.Builder(this).setCancelable(true)
                        .setMessage(R.string.str_access_permissions)
                        .setPositiveButton(R.string.dialog_ok, new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                ActivityCompat.requestPermissions(MainActivity.this,
                                        new String[] { Manifest.permission.READ_CONTACTS }, 0x01);
                            }//w ww  . ja  v a 2  s  .  c  o  m
                        }).show();

            } else {

                // No explanation needed, we can request the permission.
                ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.READ_CONTACTS },
                        0x01);

            }
        }

    if (!permissionWriteExternal)
        if (ActivityCompat.checkSelfPermission(this,
                Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {

            // Should we show an explanation?
            if (ActivityCompat.shouldShowRequestPermissionRationale(this,
                    Manifest.permission.WRITE_EXTERNAL_STORAGE)) {

                // Show an expanation to the user *asynchronously* -- don't block
                // this thread waiting for the user's response! After the user
                // sees the explanation, try again to request the permission.
                new android.app.AlertDialog.Builder(this).setCancelable(true)
                        .setMessage(R.string.str_write_external_permission)
                        .setPositiveButton(R.string.dialog_ok, new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                ActivityCompat.requestPermissions(MainActivity.this,
                                        new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, 0x02);
                            }
                        }).show();

            } else {

                // No explanation needed, we can request the permission.
                ActivityCompat.requestPermissions(this,
                        new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, 0x02);

            }
        }
}

From source file:cn.moon.superwechat.runtimepermissions.PermissionsManager.java

/**
 * Filter the permissions list://from  ww  w. j av  a 2  s.  c  om
 * If a permission is not granted, add it to the result list
 * if a permission is granted, do the granted work, do not add it to the result list
 *
 * @param activity    the activity to check permissions
 * @param permissions all the permissions names
 * @param action      the callback work object, containing what we what to do after
 *                    permission check
 * @return a list of permissions names that are not granted yet
 */
@NonNull
private List<String> getPermissionsListToRequest(@NonNull Activity activity, @NonNull String[] permissions,
        @Nullable PermissionsResultAction action) {
    List<String> permList = new ArrayList<String>(permissions.length);
    for (String perm : permissions) {
        if (!mPermissions.contains(perm)) {
            if (action != null) {
                action.onResult(perm, Permissions.NOT_FOUND);
            }
        } else if (ActivityCompat.checkSelfPermission(activity, perm) != PackageManager.PERMISSION_GRANTED) {
            if (!mPendingRequests.contains(perm)) {
                permList.add(perm);
            }
        } else {
            if (action != null) {
                action.onResult(perm, Permissions.GRANTED);
            }
        }
    }
    return permList;
}

From source file:cl.gisred.android.StandardActivity.java

private void verifPermisos() {
    if (ContextCompat.checkSelfPermission(StandardActivity.this,
            Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {

        // Should we show an explanation?
        if (ActivityCompat.shouldShowRequestPermissionRationale(StandardActivity.this,
                Manifest.permission.ACCESS_FINE_LOCATION)) {

        } else {/*  w  w  w.  j  ava 2 s.  com*/
            // No explanation needed, we can request the permission.

            ActivityCompat.requestPermissions(StandardActivity.this,
                    new String[] { Manifest.permission.ACCESS_FINE_LOCATION },
                    Util.REQUEST_ACCESS_FINE_LOCATION);
        }
    } else {
        initGeoposition();
    }

}

From source file:com.github.akinaru.hcidebugger.activity.HciDebuggerActivity.java

protected void onCreate(Bundle savedInstanceState) {

    setLayout(R.layout.debugger_activity);
    super.onCreate(savedInstanceState);

    //setup frames
    mDisplayFrame = (FrameLayout) findViewById(R.id.display_frame);
    mWaitingFrame = (FrameLayout) findViewById(R.id.waiting_frame);
    mNothingToShowTv = (TextView) findViewById(R.id.nothing_to_show);

    // Setup drawer view
    setupDrawerContent(nvDrawer);//from   ww w  .  j a va 2s  . c  o  m

    filters = new Filters(this, "", "", "", "", "");

    filters.setPacketType(prefs.getString(Constants.PREFERENCES_PACKET_TYPE_FILTER, ""));
    filters.setEventType(prefs.getString(Constants.PREFERENCES_EVENT_TYPE_FILTER, ""));
    filters.setOgf(prefs.getString(Constants.PREFERENCES_OGF_FILTER, ""));
    filters.setSubEventType(prefs.getString(Constants.PREFERENCES_SUBEVENT_FILTERS, ""));
    filters.setAddress(prefs.getString(Constants.PREFERENCES_ADVERTISING_ADDR, ""));
    mMaxPacketCount = prefs.getInt(Constants.PREFERENCES_MAX_PACKET_COUNT, Constants.DEFAULT_LAST_PACKET_COUNT);

    mScanType = ScanType.getScanType(prefs.getString(Constants.PREFERENCES_SCAN_TYPE, ""));

    mBtSnoopFilePath = prefs.getString(Constants.PREFERENCES_BTSNOOP_FILEPATH, getHciLogFilePath());

    // init Bluetooth adapter
    final BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(BLUETOOTH_SERVICE);
    mBluetoothAdapter = bluetoothManager.getAdapter();

    //init recycler view
    packetListView = (CustomRecyclerView) findViewById(R.id.packet_list);
    packetList = new ArrayList<>();
    packetAdapter = new PacketAdapter(packetList, this, new IViewHolderClickListener() {
        @Override
        public void onClick(View view) {
            int index = packetListView.getChildAdapterPosition(view);

            //launch packet description activity
            Intent intent = new Intent(HciDebuggerActivity.this, DescriptionActivity.class);

            if (packetFilteredList.size() != 0) {
                intent.putExtra(Constants.INTENT_HCI_PACKET,
                        packetFilteredList.get(index).getJsonFormattedHciPacket());
                intent.putExtra(Constants.INTENT_SNOOP_PACKET,
                        packetFilteredList.get(index).getJsonFormattedSnoopPacket());
                intent.putExtra(Constants.INTENT_PACKET_NUMBER, packetFilteredList.get(index).getNum());
                intent.putExtra(Constants.INTENT_PACKET_TS,
                        timestampFormat.format(packetFilteredList.get(index).getTimestamp().getTime()));
                intent.putExtra(Constants.INTENT_PACKET_TYPE, packetFilteredList.get(index).getDisplayedType());
                intent.putExtra(Constants.INTENT_PACKET_DEST,
                        packetFilteredList.get(index).getDest().toString());
            } else {
                intent.putExtra(Constants.INTENT_HCI_PACKET, packetList.get(index).getJsonFormattedHciPacket());
                intent.putExtra(Constants.INTENT_SNOOP_PACKET,
                        packetList.get(index).getJsonFormattedSnoopPacket());
                intent.putExtra(Constants.INTENT_PACKET_NUMBER, packetList.get(index).getNum());
                intent.putExtra(Constants.INTENT_PACKET_TS,
                        timestampFormat.format(packetList.get(index).getTimestamp().getTime()));
                intent.putExtra(Constants.INTENT_PACKET_TYPE, packetList.get(index).getDisplayedType());
                intent.putExtra(Constants.INTENT_PACKET_DEST, packetList.get(index).getDest().toString());
            }
            startActivity(intent);
        }
    });

    //set layout manager
    packetListView.setLayoutManager(new GridLayoutManager(this, 1, LinearLayoutManager.VERTICAL, false));

    //set line decoration
    packetListView.addItemDecoration(new SimpleDividerItemDecoration(getApplicationContext()));

    packetListView.setAdapter(packetAdapter);

    //setup swipe refresh
    mSwipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swiperefresh);
    mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            refresh();
        }
    });

    //setup floating button
    final FloatingActionButton upFloatingBtn = (FloatingActionButton) findViewById(R.id.updown_btn);
    upFloatingBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            // Click action
            if (floatBtnDown) {
                packetListView.scrollToPosition(packetListView.getAdapter().getItemCount() - 1);
                floatBtnDown = false;
                upFloatingBtn.setImageResource(R.drawable.ic_arrow_upward);
            } else {
                packetListView.scrollToPosition(0);
                floatBtnDown = true;
                upFloatingBtn.setImageResource(R.drawable.ic_arrow_downward);
            }

        }
    });

    if (Build.VERSION.SDK_INT >= 23) {
        if (checkSelfPermission(
                Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
            requestPermissions(new String[] { Manifest.permission.READ_EXTERNAL_STORAGE },
                    REQUEST_PERMISSION_READ_EXTERNAL);
        } else {
            bindService();
        }
    } else {
        bindService();
    }
}

From source file:com.aftabsikander.permissionassist.PermissionAssistant.java

private static void notifyAlreadyHasPermissions(Object object, int requestCode, @NonNull String[] perms) {
    int[] grantResults = new int[perms.length];
    for (int i = 0; i < perms.length; i++) {
        grantResults[i] = PackageManager.PERMISSION_GRANTED;
    }//  w  w w. ja  v  a 2 s.  c om

    onRequestPermissionsResult(requestCode, perms, grantResults, object);
}

From source file:ca.ualberta.cs.swapmyride.View.AddInventoryActivity.java

/**
 * This calls the activity to take the photo.
 *//*www . j  av a2 s.co m*/

private void dispatchTakePictureIntent() {

    // http://developer.android.com/training/permissions/requesting.html
    // Here, thisActivity is the current activity
    if (ContextCompat.checkSelfPermission(AddInventoryActivity.this,
            Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {

        // Should we show an explanation?
        if (ActivityCompat.shouldShowRequestPermissionRationale(AddInventoryActivity.this,
                Manifest.permission.CAMERA)) {

            // Show an explanation to the user *asynchronously* -- don't block
            // this thread waiting for the user's response! After the user
            // sees the explanation, try again to request the permission.

        } else {

            // No explanation needed, we can request the permission.

            ActivityCompat.requestPermissions(AddInventoryActivity.this,
                    new String[] { Manifest.permission.CAMERA }, MY_PERMISSIONS_REQUEST_CAMERA);

            // MY_PERMISSIONS_REQUEST_READ_CONTACTS is an
            // app-defined int constant. The callback method gets the
            // result of the request.
        }
    } else {

        Log.i("TakingPictureIntent", "Trying to take a photo");
        Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        if (takePictureIntent.resolveActivity(getPackageManager()) != null
                && checkHasCamera(getApplicationContext())) {

            startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
        }
    }
}