+-

我用ndk构建了一些命令行工具,并在/ data / local / tmp中执行了它.现在,当我在命令行工具中调用一些OpenSLES API时,它提示我“需要 android.permission.RECORD_AUDIO”:
W/AudioRecord( 4226): AUDIO_INPUT_FLAG_FAST denied by client
W/ServiceManager( 207): Permission failure: android.permission.RECORD_AUDIO from uid=2000 pid=4226
E/ ( 207): Request requires android.permission.RECORD_AUDIO
D/PowerManagerService( 964): handleSandman: canDream=false, mWakefulness=Asleep
E/AudioFlinger( 207): openRecord() permission denied: recording not allowed
E/AudioRecord( 4226): AudioFlinger could not create record track, status: -1
E/libOpenSLES( 4226): android_audioRecorder_realize(0x453430) error creating AudioRecord object
W/libOpenSLES( 4226): Leaving Object::Realize (SL_RESULT_CONTENT_UNSUPPORTED)
我也尝试用pm grant授予shell:
pm grant "com.android.shell" android.permission.RECORD_AUDIO
pm grant "com.android.shell" android.permission.RECORD_AUDIO
pm grant "com.android.shell" android.permission.RECORD_AUDIO
Operation not allowed: java.lang.SecurityException: Package com.android.shell has not requested permission android.permission.RECORD_AUDIO
更改/system/etc/permissions/platform.xml也不起作用.
我可以在Android Shell中调试OpenSLES演示吗?我如何在shell中获得更多许可.
我必须为每个实验代码片段创建一个jni和java项目,并在更改某些C接口时一起对其进行修改吗?
我可以从外壳程序的命令工具中直接访问RECORD_AUDIO,CAMERA吗?
最佳答案
这是行动中的 new permissions model in Android Marshmallow.要获得此权限,您需要提示用户进行授予.这是我的工作:
>每当我需要RECORD_AUDIO权限时,我都会检查我是否拥有它:
private boolean hasRecordAudioPermission(){
boolean hasPermission = (ContextCompat.checkSelfPermission(this,
Manifest.permission.RECORD_AUDIO) == PackageManager.PERMISSION_GRANTED);
log("Has RECORD_AUDIO permission? " + hasPermission);
return hasPermission;
}
>如果我没有,请提出要求
private void requestRecordAudioPermission(){
String requiredPermission = Manifest.permission.RECORD_AUDIO;
// If the user previously denied this permission then show a message explaining why
// this permission is needed
if (ActivityCompat.shouldShowRequestPermissionRationale(this,
requiredPermission)) {
showToast("This app needs to record audio through the microphone....");
}
// request the permission.
ActivityCompat.requestPermissions(this,
new String[]{requiredPermission},
PERMISSIONS_REQUEST_RECORD_AUDIO);
}
@Override
public void onRequestPermissionsResult(int requestCode,
String permissions[], int[] grantResults) {
// This method is called when the user responds to the permissions dialog
}
点击查看更多相关文章
转载注明原文:如何授予Android Shell用户更多权限? - 乐贴网