当前位置: 首页>>代码示例>>Java>>正文


Java ActivityCompat.requestPermissions方法代码示例

本文整理汇总了Java中android.support.v4.app.ActivityCompat.requestPermissions方法的典型用法代码示例。如果您正苦于以下问题:Java ActivityCompat.requestPermissions方法的具体用法?Java ActivityCompat.requestPermissions怎么用?Java ActivityCompat.requestPermissions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.support.v4.app.ActivityCompat的用法示例。


在下文中一共展示了ActivityCompat.requestPermissions方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: requestPermissionIfNeeded

import android.support.v4.app.ActivityCompat; //导入方法依赖的package包/类
private static boolean requestPermissionIfNeeded(String permission, Activity activity) {
    if (ContextCompat.checkSelfPermission(activity, permission) != PackageManager.PERMISSION_GRANTED) {
        ActivityCompat.requestPermissions(activity, new String[]{permission}, 1);
        return true;
    }
    return false;
}
 
开发者ID:ROKOLabs,项目名称:ROKOmoji.Emoji.Keyboard.App-Android,代码行数:8,代码来源:KeyboardService.java

示例2: show

import android.support.v4.app.ActivityCompat; //导入方法依赖的package包/类
/**
 * This method creates and display file picker dialog
 */
private void show() {
    if (ActivityCompat.checkSelfPermission(mActivity,
            Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
        ActivityCompat.requestPermissions(mActivity, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
                STORAGE_PERMISSIONS);
        return;
    }

    AlertDialog.Builder alertBuilder = new AlertDialog.Builder(mActivity);
    final AlertDialog alertdialog = alertBuilder.create();
    mPickerViewModel.setAlertDialog(alertdialog);

    PickerDialogBinding binding = DataBindingUtil.inflate(LayoutInflater.from(mActivity),
            R.layout.picker_dialog, null, false);
    binding.setVariable(BR.viewModel, mPickerViewModel);

    alertdialog.setView(binding.getRoot());
    alertdialog.show();
}
 
开发者ID:Applandeo,项目名称:Material-File-Picker,代码行数:23,代码来源:FilePicker.java

示例3: requestRuntimePermission

import android.support.v4.app.ActivityCompat; //导入方法依赖的package包/类
public static void requestRuntimePermission(Activity activity, String[] permissions,
                                            OnRequestPermissionsListener listener) {
    if (null == activity) {
        return;
    }
    mListener = listener;
    List<String> permissionList = new ArrayList<>();
    for (String permission : permissions) {
        if (ContextCompat.checkSelfPermission(activity, permission)
                != PackageManager.PERMISSION_GRANTED) {

            permissionList.add(permission);
        }
    }
    if (!permissionList.isEmpty()) {
        ActivityCompat.requestPermissions(activity,
                permissionList.toArray(new String[permissionList.size()]),
                PERMISSION_REQUEST_CODE);
    } else {
        mListener.onGranted();
    }
}
 
开发者ID:InnoFang,项目名称:Android-Code-Demos,代码行数:23,代码来源:RequestPermissions.java

示例4: onStart

import android.support.v4.app.ActivityCompat; //导入方法依赖的package包/类
@Override
protected void onStart() {
    Log.i(getClass().getName(), "onStart");
    super.onStart();

    // Ask for permissions
    int permissionCheckWriteExternalStorage = ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE);
    if (permissionCheckWriteExternalStorage != PackageManager.PERMISSION_GRANTED) {
        ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, PERMISSION_REQUEST_READ_EXTERNAL_STORAGE);
        return;
    }

    ContentProvider.initializeDb(this);

    Intent intent = new Intent(this, WriteNumberActivity.class);
    startActivity(intent);

    finish();
}
 
开发者ID:elimu-ai,项目名称:egma-handwriting-numbers,代码行数:20,代码来源:MainActivity.java

示例5: checkPermission

import android.support.v4.app.ActivityCompat; //导入方法依赖的package包/类
private void checkPermission(int requestCode) {
    String permission = null;
    if (requestCode == 0) {
        permission = Manifest.permission.READ_EXTERNAL_STORAGE;
    } else {
        permission = Manifest.permission.WRITE_EXTERNAL_STORAGE;
    }
    if (ContextCompat.checkSelfPermission(this, permission) != PackageManager.PERMISSION_GRANTED) {
        ActivityCompat.requestPermissions(this,
                new String[]{permission},
                requestCode);
    } else {
        if (requestCode == Constants.READ_EXTERNAL_PERMISSION_REQUEST_CODE) {
            checkPermission(Constants.WRITE_EXTERNAL_PERMISSION_REQUEST_CODE);
        } else {
            saveExpansion();
        }
    }
}
 
开发者ID:SlotNSlot,项目名称:SlotNSlot_Android,代码行数:20,代码来源:LandingPageActivity.java

示例6: onCreate

import android.support.v4.app.ActivityCompat; //导入方法依赖的package包/类
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_audio);
        ButterKnife.bind(this);
        currentState = Status.START;
        myHandler = new Handler();
        audioMgr = (AudioManager) getSystemService(AUDIO_SERVICE);
        Intent incoming = getIntent();
        if (incoming.hasExtra("AUDIO_PATH")) {
            audioFilePath = incoming.getStringExtra("AUDIO_PATH");
//            audioFilePath = dataUri.getPath();
            recordBtn.setEnabled(true);
        } else {
            recordBtn.setEnabled(false);
        }
        int currentPerm = ActivityCompat.checkSelfPermission(this,
                permArr[0]);
        if (currentPerm == PackageManager.PERMISSION_DENIED) {
            ActivityCompat.requestPermissions(this, permArr, AUDIO_PERMISSION_REQUEST);
        }
    }
 
开发者ID:gvsucis,项目名称:mobile-app-dev-book,代码行数:23,代码来源:AudioActivity.java

示例7: onCreate

import android.support.v4.app.ActivityCompat; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    imageView1 = (ImageView) findViewById(R.id.standard_list_imageview1);
    imageView2 = (ImageView) findViewById(R.id.standard_list_imageview2);
    imageView3 = (ImageView) findViewById(R.id.standard_list_imageview3);
    imageView4 = (ImageView) findViewById(R.id.standard_list_imageview4);


    if (ContextCompat.checkSelfPermission(MainActivity.this,
            Manifest.permission.READ_EXTERNAL_STORAGE)
            != PackageManager.PERMISSION_GRANTED) {
        ActivityCompat.requestPermissions(MainActivity.this,
                new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
                100);
    }
}
 
开发者ID:fs-opensource,项目名称:android-glide-youtube-sample,代码行数:20,代码来源:MainActivity.java

示例8: requestPermissions

import android.support.v4.app.ActivityCompat; //导入方法依赖的package包/类
private void requestPermissions(String... permissions) {
    ActivityCompat.requestPermissions(this, permissions, PERMISSION_REQUEST_CODE);
}
 
开发者ID:FallenCrood,项目名称:Review-,代码行数:4,代码来源:PermissionsActivity.java

示例9: requestStoragePermission

import android.support.v4.app.ActivityCompat; //导入方法依赖的package包/类
/**
 * 申请权限 SD卡的读写权限
 * @param activity
 */
private void requestStoragePermission(Activity activity){
   //检测权限
    int permission = ContextCompat.checkSelfPermission(activity.getApplicationContext(), Manifest.permission.WRITE_EXTERNAL_STORAGE);
    if (permission!= PackageManager.PERMISSION_GRANTED){
        //没有权限 则申请权限  弹出对话框
        ActivityCompat.requestPermissions(activity,PERMISSION_STORAGES,REQUEST_CODE_STORAGE);
    }
}
 
开发者ID:guzhigang001,项目名称:Bailan,代码行数:13,代码来源:SplashActivity.java

示例10: onCreate

import android.support.v4.app.ActivityCompat; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_bluetooth_devices);
    initializeScreen();

    //check if the device has a bluetooth or not
    //and show Toast message if it does't have
    mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    bluetoothDevicesAdapter = new BluetoothDevicesAdapter(this, bluetoothDevicesNamesList);

    if (mBluetoothAdapter == null) {
        Toast.makeText(this, R.string.does_not_have_bluetooth, Toast.LENGTH_LONG).show();
        finish();
    } else if (!mBluetoothAdapter.isEnabled()) {
        Intent enableIntentBluetooth = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
        startActivityForResult(enableIntentBluetooth, REQUEST_ENABLE_BT);
    } else if (mBluetoothAdapter.isEnabled()) {
        PairedDevicesList();
    }

    setBroadCastReceiver();

    //request location permission for bluetooth scanning for android API 23 and above
    ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, REQUEST_ENABLE_FINE_LOCATION);


    //press the button to start search new Devices
    searchForNewDevices.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            searchForNewDevices.setEnabled(false);
            bluetoothDevicesAdapter.clear();
            PairedDevicesList();
            NewDevicesList();
        }
    });

}
 
开发者ID:Ahmed-Abdelmeged,项目名称:Bluetooth-send,代码行数:40,代码来源:BluetoothDevices.java

示例11: onCreate

import android.support.v4.app.ActivityCompat; //导入方法依赖的package包/类
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

    setContentView(R.layout.activity_main);

    if (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.CAMERA)
            != PackageManager.PERMISSION_GRANTED) {
        Log.i("permission", "request CAMERA");
        ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.CAMERA}, REQUEST_CAMERA);
    }else {
        Log.i("permission", "CAMERA already granted");
        camera_granted = true;
    }
    if (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE)
            != PackageManager.PERMISSION_GRANTED) {
        Log.i("permission", "request EXTERNAL_STROAGE");
        ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, REQUEST_EXTERNAL_STROAGE);
    }else {
        Log.i("permission", "EXTERNAL_STROAGE already granted");
        read_external_storage_granted = true;
    }

    OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_3_2_0, this, mLoaderCallback);

    mOpenCvCameraView = (CameraBridgeViewBase) findViewById(R.id.java_surface_view);
    mOpenCvCameraView.setVisibility(SurfaceView.VISIBLE);
    mOpenCvCameraView.setCvCameraViewListener(this);

    Log.d("OCR", "onCreate done");

}
 
开发者ID:johnhany,项目名称:MOAAP,代码行数:35,代码来源:MainActivity.java

示例12: performPermissionDeniedAction

import android.support.v4.app.ActivityCompat; //导入方法依赖的package包/类
private void performPermissionDeniedAction(DeviceInfoBean deviceInfo) {
    if (ContextCompat.checkSelfPermission(getBaseContext(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        ActivityCompat.requestPermissions((Activity) mContext,
                new String[]{Manifest.permission.ACCESS_COARSE_LOCATION},
                REQUEST_ACCESS_COARSE_LOCATION);
    } else {
        startDeviceConnection(deviceInfo, healthCareReceiver);
    }
}
 
开发者ID:Welloculus,项目名称:MobileAppForPatient,代码行数:10,代码来源:DeviceListActivity.java

示例13: requestPermissionForRecord

import android.support.v4.app.ActivityCompat; //导入方法依赖的package包/类
public void requestPermissionForRecord() {
    if (ActivityCompat.shouldShowRequestPermissionRationale(activity, Manifest.permission.RECORD_AUDIO)) {
        ActivityCompat.requestPermissions(activity, new String[]{Manifest.permission.RECORD_AUDIO}, RECORD_PERMISSION_REQUEST_CODE);
    } else {
        ActivityCompat.requestPermissions(activity, new String[]{Manifest.permission.RECORD_AUDIO}, RECORD_PERMISSION_REQUEST_CODE);
    }
}
 
开发者ID:PacktPublishing,项目名称:Expert-Android-Programming,代码行数:8,代码来源:MarshmallowPermission.java

示例14: checkPermissionAndDonateWeixin

import android.support.v4.app.ActivityCompat; //导入方法依赖的package包/类
private void checkPermissionAndDonateWeixin() {
    //检测微信是否安装
    if (!WeiXinDonate.hasInstalledWeiXinClient(this)) {
        Toast.makeText(this, "未安装微信客户端", Toast.LENGTH_SHORT).show();
        return;
    }
    if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
        //已经有权限
        showDonateTipDialog();
    } else {
        ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, REQUEST_CODE);
    }
}
 
开发者ID:didikee,项目名称:AndroidDonate,代码行数:14,代码来源:MainActivity.java

示例15: getDeviceLoc

import android.support.v4.app.ActivityCompat; //导入方法依赖的package包/类
/**
 * ref: https://chantisandroid.blogspot.ca/2017/06/get-current-location-example-in-android.html
 * @return current location
 */
private Location getDeviceLoc() {
    service = (LocationManager) getSystemService(LOCATION_SERVICE);
    if (ActivityCompat.checkSelfPermission(ViewHabitEvent.this, Manifest.permission.ACCESS_FINE_LOCATION)
            != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission
            (ViewHabitEvent.this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        ActivityCompat.requestPermissions(ViewHabitEvent.this,
                new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, REQUEST_LOCATION);

    }
    else {

        Location location = service.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
        Location location1 = service.getLastKnownLocation(LocationManager.GPS_PROVIDER);
        Location location2 = service.getLastKnownLocation(LocationManager. PASSIVE_PROVIDER);
        if (location != null) {
            return location;
        }
        else  if (location1 != null) {
            return location1;
        }
        else  if (location2 != null) {
            return location2;
        }
    }
    return null;
}
 
开发者ID:CMPUT301F17T23,项目名称:routineKeen,代码行数:31,代码来源:ViewHabitEvent.java


注:本文中的android.support.v4.app.ActivityCompat.requestPermissions方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。