Example usage for android.app Activity requestPermissions

List of usage examples for android.app Activity requestPermissions

Introduction

In this page you can find the example usage for android.app Activity requestPermissions.

Prototype

public final void requestPermissions(@NonNull String[] permissions, int requestCode) 

Source Link

Document

Requests permissions to be granted to this application.

Usage

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);
}