【原】安卓麦克风等权限提示

2017-06-30  本文已影响2396人  紫荆逸

以开启麦克风权限为例

1.在AndroidManifest.xml中加上

<uses-permission android:name="android.permission.RECORD_AUDIO"/>

2.在AppActivity.java文件的protected voidonCreate(Bundle savedInstanceState) {}方法里可加入以下代码:

PackageManager pkgManager= getPackageManager();

boolean audioSatePermission =

pkgManager.checkPermission(Manifest.permission.RECORD_AUDIO, getPackageName()) == PackageManager.PERMISSION_GRANTED;

if(Build.VERSION.SDK_INT>=23&&!audioSatePermission) {

requestPermission();

}

3.requestPermission();方法的具体写法:

private void requestPermission() {

ActivityCompat.requestPermissions(this,newString[] {Manifest.permission.RECORD_AUDIO},

REQUEST_PERMISSION);

}
上一篇 下一篇

猜你喜欢

热点阅读