List of usage examples for android.app Activity requestPermissions
public final void requestPermissions(@NonNull String[] permissions, int requestCode)
From source file:kr.wdream.ui.DialogsActivity.java
@TargetApi(Build.VERSION_CODES.M) private void askForPermissons() { Activity activity = getParentActivity(); if (activity == null) { return;//from w w w.j a v a2 s . c o m } ArrayList<String> permissons = new ArrayList<>(); if (activity.checkSelfPermission(Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED) { permissons.add(Manifest.permission.READ_CONTACTS); permissons.add(Manifest.permission.WRITE_CONTACTS); permissons.add(Manifest.permission.GET_ACCOUNTS); } if (activity.checkSelfPermission( Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { permissons.add(Manifest.permission.READ_EXTERNAL_STORAGE); permissons.add(Manifest.permission.WRITE_EXTERNAL_STORAGE); } String[] items = permissons.toArray(new String[permissons.size()]); activity.requestPermissions(items, 1); }